// JavaScript Document
var viewer_info;
var owner_info;
var owner_id;
var viewer_id;
var viewer_friends;
var err_conunt=0;
var pname_arr=new Array();
var puid_arr=new Array();
var thumb_arr=new Array();
var puid_url=new Array();
var has_app_id=new Array();
var has_app_name=new Array();
var has_app_thumb=new Array();
var has_noapp_id=new Array();
var has_noapp_name=new Array();
var has_noapp_thumb=new Array();
var appdomain;
var appPageURL="http://orkut.auciti.com:8008/hangout";
var appServletURL="http://orkut.auciti.com:8008/hangout";
var appId='45641817140';
var appid='45641817140';
var domainURL;
var pageParams = gadgets.views.getParams();
var currentview = gadgets.views.getCurrentView();
var c;
var prefs = new gadgets.Prefs();
var urlParams = ['ctry=', prefs.getCountry(), '&lang=', prefs.getLang()];
var cntr="";
var arr= new Array();
var arr = getArgs();
var hostid;
var regex=/uid=([^&#]+)/;
var _address;
var media;
var jsonvar;
var hid;
var rsvp_hid ='';
var param;
var canceluids=new Array();
var await_arr=new Array();
var total=0;
var postdata ={};
var params = {};
var names_arr=new Array();
var ids_arr=new Array();
var tid_arr=new Array();
var name_string=new Array();
var id_string=new Array();
var tid_string=new Array();
var records=0;
var p=0;
var pages=0;
var p_g=1;
var pos=new Array();
var val='';
var paging="";
var flag;
var _default_loc='';
var token;
var showPastData;
//var ownercountry;
gadgets.util.registerOnLoadHandler(gethostid);
function debug(msg){
	debugwindow=window.open('','debug','toolbar=1,resizable=1,width=500,height=500,scrollbars=yes');
	debugwindow.document.writeln(msg+'<br>');
	}	
function displayMsg(msg)
{
	debug("displayMsg");
	return prefs.getMsg(msg);
}
if(arr.length!=0)
{
	var text= arr[1].substring(7);
	var domain=text.split(".");
	if(domain[0]=='sandbox')
	{
		appdomain=domain[0];
	}
	else
	{
		appdomain="www";
	}
	//alert(prefs.getCountry());
	domainURL="http://"+appdomain+".orkut.com";
}
function getArgs()
{
	debug("getArgs");
	var args = new Object();
	var arr = new Array();
	var query = location.search.substring(1);
	var pairs = query.split("&");
	for(var i = 0; i < pairs.length; i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos == -1) 
		continue; 
		var argname = pairs[i].substring(0,pos); 
		var value = pairs[i].substring(pos+1); 
		args[argname] = unescape(value); 
		arr.push(args[argname]);
	} 	
	return arr; 
} 
function fetchAppPage()
{
	debug("fetchAppPage");
  	var params = {};
	var postdata={};
    params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
    params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.HTML;
   	params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
  	if(c==1)
	{	
		if(currentview.getName()=='canvas')
		{
			getHtmlPage('hangout','','','yes','')
		}
		else 
		{
			var refreshInterval=0;	
			var url=appPageURL+'/profile_view.html';
			var ts = new Date().getTime();
			var sep = "?";
			if (refreshInterval && refreshInterval > 0) 
			{
				ts = Math.floor(ts / (refreshInterval * 1000));
			}
			if (url.indexOf("?") > -1) 
			{
				sep = "&";
			}
			 url = [ url, sep, "nocache=", ts ].join("");	
			 gadgets.io.makeRequest(url,		
			  function(response) 
			  {		
				if(typeof(response.text) != 'undefined' || response.text!="" || response.errors[0]!="Error 500" || response.text != '{}' || response.text != null || response.errors[0]!="Error 400")
				{
					if(document.getElementById('app_main_canvas'))
					{
						document.getElementById('app_main_canvas').innerHTML = response.text;
						getHangouts('scheduled',1,1,'no');
					}
					else
					{
						fetchAppPage();
					}
				}
				else
				{
					err_conunt++;
					if(err_conunt<3)
					{						
						fetchAppPage();
					}
					else
					{
						var err_desc=Customized_ErrorMessages('orkut');
						if(document.getElementById('app_main_canvas'))
						{
							document.getElementById('app_main_canvas').innerHTML=err_desc+"<a href='javascript:window.history.go(0);' text-decoration='none'><b style='color:#002569'> "+displayMsg('Click')+" </b></a> "+displayMsg('try');
							err_conunt=0;
						}
					}				
				}
		   },params );
		}	
	}
	else if(c==0)
	{
		var refreshInterval=0;
		var url;
		if(currentview.getName()=='canvas')
		{
			if(prefs.getLang()=='pt')
			{
				url=appPageURL+'/prt_noFriends.html';
			}
			else if(prefs.getLang()=='en')
			{
				url=appPageURL+'/noFriends.html';	
			}
			else
			{
				url=appPageURL+'/noFriends.html';
			}
			
		}
		else
		{
			url=appPageURL+'/profile_view.html';
		}
		var ts = new Date().getTime();
		var sep = "?";
		if (refreshInterval && refreshInterval > 0) 
		{
			ts = Math.floor(ts / (refreshInterval * 1000));
		}
		if (url.indexOf("?") > -1) 
		{
			sep = "&";
		}
		 url = [ url, sep, "nocache=", ts ].join("");	
		 gadgets.io.makeRequest(url,		
		  function(response) 
		  {		
			if(typeof(response.text) != 'undefined' || response.text!="" || response.errors[0]!="Error 500" || response.text != '{}' || response.text != null || response.errors[0]!="Error 400")
			{
				if(document.getElementById('app_main_canvas'))
				{
					document.getElementById('app_main_canvas').innerHTML = response.text;
					if(currentview.getName()!='canvas')
					{
						if(document.getElementById('profile_scheduled'))
						{
							document.getElementById('profile_scheduled').innerHTML = '<table cellspacing="0" cellpadding="0" border="0" width="490px"><tr ><td class="profilebgtop" height="25px"><table border="0" cellspacing="0" cellpadding="0" align="center" valign="middle" width="100%" ><tr><td style="padding-left:10px; font-size:11px" class="pageheading" align="left" ></td></tr></table></td></tr><tr class="profilebgmiddle"><td width="490px"><table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" valign="top" ><tr><td valign="top" align="center" ><img src="'+appPageURL+'/images/NoFriendsProfile.gif" border="0" /></td></tr></table></td></tr><tr><td class="profilebgbottom" height="11px" valign="top" align="center"></td></tr><tr><td align="right" valign="bottom" style="color:#747474; font-size:10px; padding-right:5px">by <a href="http://www.auciti.com" target="_blank" style="color:#747474">auciti.com</a> | <a target="_blank" href="http://www.orkut.com/Community.aspx?cmm=47593020">Discussion and Feedback</a></td></tr></table>';	
						}
					}
				}
			}
			else
			{
				err_conunt++;
				if(err_conunt<3)
				{						
					fetchAppPage();
				}
				else
				{
					var err_desc=Customized_ErrorMessages('servlet');
					alert(err_desc);
					err_conunt=0;
				}				
			}
	   },params );
	}
}
function getUserID_fromURL(profile_url)
{
	debug("getUserID_fromURL");
    var result = profile_url.match(regex);
    if (result.length == 2) {
        return result[1];
    }
	else
	{
        return 'unknown_user_id';
    }
}
function gotoCanvas(addParams)
{
	debug("gotoCanvas");
	var views = gadgets.views.getSupportedViews();
	if(typeof(owner_id) != 'undefined')
	{
        gadgets.views.requestNavigateTo(views.canvas,addParams);
    }
	else
	{
       window.parent.location = domainURL+'/Application.aspx?uid='+d+'&appId='+appId;
		gotoAddApp();
    }
}

function gotoAddApp()
{
	debug("gotoAddApp");
   	var params = {};
	params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
	params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
	params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.HTML;
	if(currentview.getName()=='canvas')
	{
		var add_app="";
		if(prefs.getLang()=='pt')
		{
			add_app='prt_addapp.html';
		}
		else if(prefs.getLang()=='en')
		{
			add_app='addapp.html';	
		}
		else
		{
			add_app='addapp.html';
		}
	    gadgets.io.makeRequest(appPageURL+'/'+add_app,function(response){if(typeof(response.text) != 'undefined' || response.text!="" || response.errors[0]!="Error 500" || response.text != '{}' || response.text != null || response.errors[0]!="Error 400"){document.getElementById('app_main_canvas').innerHTML = response.data;}},params);
	}
	else
	{
		var add_app="";
		if(prefs.getLang()=='pt')
		{
			add_app='profile_prt_addapp.html';
		}
		else if(prefs.getLang()=='en')
		{
			add_app='profile_addapp.html';	
		}
		else
		{
			add_app='profile_addapp.html';
		}
		 gadgets.io.makeRequest(appPageURL+'/'+add_app,function(response) 
		  {			
			if(typeof(response.text) != 'undefined' || response.text!="" || response.errors[0]!="Error 500" || response.text != '{}' || response.text != null || response.errors[0]!="Error 400")
			{
				if(document.getElementById('app_main_canvas'))
				{
					document.getElementById('app_main_canvas').innerHTML = response.data;				
				}
			}
	   },params );
	}
}

function addapp()
{
	debug("addapp");
	//window.parent.location=domainURL+'/AppInfo.aspx?appId='+appid;
	window.top.location=domainURL+'/AppInfo.aspx?appId='+appid;
}

function gethostid()
{
	debug("gethostid");
	try
	{
		var req = opensocial.newDataRequest();
		var opt_params = {};
		
		opt_params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [
		opensocial.Person.Field.PROFILE_URL
		];
		opt_params[opensocial.DataRequest.PeopleRequestFields.MAX] = 1000;
		opt_params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] =
			[opensocial.Person.Field.PROFILE_URL,opensocial.Person.Field.GENDER,opensocial.Person.Field.ADDRESSES,opensocial.Person.Field.DATE_OF_BIRTH];
		req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER, opt_params), "viewer");
		req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER, opt_params), "owner");
		req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS, opt_params), "viewer_friends");
		req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.OWNER_FRIENDS, opt_params), "owner_friends");
		req.send(hangoutsresponse);

		
		var opt={};
		opt[opensocial.DataRequest.PeopleRequestFields.FILTER]= opensocial.DataRequest.FilterType.HAS_APP;
		opt[opensocial.DataRequest.PeopleRequestFields.MAX] = 1000;
		var req_has_app = opensocial.newDataRequest();
		req_has_app.add(req_has_app.newFetchPeopleRequest(opensocial.DataRequest.Group.OWNER_FRIENDS, opt), "has_app_owner_friends");
		req_has_app.send(
			function(data)
			{
				if(typeof(data.text) != 'undefined' || data.text!="" || data.errors[0]!="Error 500" || data.text != '{}' || data.text != null || data.errors[0]!="Error 400")
				{
					var has_app_owner_friends =data.get("has_app_owner_friends").getData();
					var ind=0;
					for(var i=0;i<puid_arr.length-1;i++)
					{
						has_noapp_id.push(puid_arr[i+1]);
						has_noapp_name.push(pname_arr[i+1]);
						has_noapp_thumb.push(thumb_arr[i+1]);				
					}
					has_app_owner_friends.each
					(
						function(friend)
						{	
							has_app_id[ind]=friend.getId();
							has_app_name[ind]=friend.getDisplayName();
							if(friend.getField(opensocial.Person.Field.THUMBNAIL_URL)!="http://img3.orkut.com/images/img/i_nophoto128.gif")
							{
								has_app_thumb[ind]=friend.getField(opensocial.Person.Field.THUMBNAIL_URL);
							}
							else
							{
								has_app_thumb[ind]=appPageURL+"/images/nophoto.gif";
							}
							ind++;
						}
					 );
					for(var i=1;i<has_app_id.length;i++)
					{
						for(var j=0;j<has_noapp_id.length;j++)
						{
							if(has_app_id[i]==has_noapp_id[j])
							{
								has_noapp_id.splice(j,1);
								has_noapp_name.splice(j,1);
								has_noapp_thumb.splice(j,1);	
							}
						}
					}
				}
				else
				{
					gethostid();
				}
			}
		);
	}
	catch(err)
	{
		err_conunt++;
		if(err_conunt<3)
		{						
			gethostid();
		}
		else
		{
			if(typeof(err.description)=='undefined');
			{
				var err_desc=Customized_ErrorMessages('orkut');
				alert(err_desc);
				
			}
				err_conunt=0;
		}	
	}
}
var d;
function hangoutsresponse(data)
{
	debug("hangoutsresponse");
	try
	{
		var arr_index=0;
		if(data.get("viewer")!= null)
		{
			viewer_info = data.get("viewer").getData();
			if(viewer_info==null)
			{	
				if(data.get("owner")!= null)
				{ 
					d = (((data.get("owner").getData()).getField(opensocial.Person.Field.PROFILE_URL)).match(regex))[1];
				}
				gotoAddApp();
			}
			else
			{
				viewer_id = viewer_info.getId();
			}
		}

		if(viewer_info!=null)
		{
			if(data.get("owner")!= null)
			{ 
				owner_info = data.get("owner").getData();
				if(owner_info!=null)
				{	
					owner_id = owner_info.getId();
				}
			}
			if(viewer_id!=owner_id)
			{
				hostid=	viewer_info.getId();
				puid_arr[0]=hostid;
				profile_url = viewer_info.getField(opensocial.Person.Field.PROFILE_URL);
				/*result = profile_url.match(regex);
				puid_host = result[1]; 
				
*/				puid_url[0]=escape(profile_url);
				pname_arr[0]=viewer_info.getDisplayName();
				thumb_arr[0]=viewer_info.getField(opensocial.Person.Field.THUMBNAIL_URL);
				//ownercountry=viewer_info.getField(opensocial.Person.Field.ADDRESSES);
				var viewer_friends = data.get("viewer_friends").getData();
				viewer_friends.each
				(
					function(person) 
					{
						var uid =  person.getId();
						puid_arr[arr_index+1]=uid;
						var name = person.getDisplayName(); 											
						pname_arr[arr_index+1]=name;
						var profile_friend = person.getField(opensocial.Person.Field.PROFILE_URL);
						/*var res = profile_friend.match(regex);
						var puid_friends = res[1];*/
						puid_url[arr_index+1]=escape(profile_friend);
						var thumb = person.getField(opensocial.Person.Field.THUMBNAIL_URL);
						if(thumb=="http://img3.orkut.com/images/img/i_nophoto128.gif")
						{
							thumb=appPageURL+"/images/nophoto.gif";	
						}
						thumb_arr[arr_index+1]=thumb;
						arr_index=arr_index+1;
					}	
				);
			}
			else
			{
				hostid=owner_info.getId();
				puid_arr[0]=hostid;
				profile_url = owner_info.getField(opensocial.Person.Field.PROFILE_URL);
				/*result = profile_url.match(regex);
				puid_host = result[1]; */
				puid_url[0]=escape(profile_url);
				pname_arr[0]=owner_info.getDisplayName();
				thumb_arr[0]=owner_info.getField(opensocial.Person.Field.THUMBNAIL_URL);
				//ownercountry=owner_info.getField(opensocial.Person.Field.ADDRESSES);
				var owner_friends = data.get("owner_friends").getData();
				owner_friends.each
				(
					function(person) 
					{
						var uid =  person.getId();
						puid_arr[arr_index+1]=uid;
						var name = person.getDisplayName(); 
						pname_arr[arr_index+1]=name;
						var profile_friend = person.getField(opensocial.Person.Field.PROFILE_URL);
						/*var res = profile_friend.match(regex);
						var puid_friends = res[1];*/
						puid_url[arr_index+1]=escape(profile_friend);
						var thumb = person.getField(opensocial.Person.Field.THUMBNAIL_URL);
						if(thumb=="http://img3.orkut.com/images/img/i_nophoto128.gif")
						{
							thumb=appPageURL+"/images/nophoto.gif";	
						}
						thumb_arr[arr_index+1]=thumb;
						arr_index=arr_index+1;
					}	
				);
			}
			
			if(puid_arr.length==1)
			{
				c = 0;	
			}
			else
			{
				c = 1;	
			}
			if(currentview.getName()=='canvas')
			{
				fetchAppPage();
			}
			else
			{
				fetchAppPage();
			}
		}
	}
	catch(err)
	{
		//alert(err);
		err_conunt++;
		if(err_conunt<3)
		{						
			//gethostid();
		}
		else
		{
			if(typeof(err.description)=='undefined');
			{
				var err_desc=Customized_ErrorMessages('orkut');
			}
				err_conunt=0;
		}		
	}
}
function Customized_ErrorMessages(ErrorType)
{
	debug("Customized_ErrorMessages");
	switch(ErrorType)
	{
		case 'orkut':
			return displayMsg("orkut");
			break;

		case 'servlet':
			return displayMsg("server");
			break;
	}
}
function post_params()
{
	debug("post_params");
	params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
	params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
	params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;	
};

function pushOwnerData()
{
	debug("pushOwnerData");
	var refreshInterval=0;
	var url=appServletURL+"/PushOwnerData?"+ urlParams.join('');
	var ts = new Date().getTime();
	var sep = "?";
	if (refreshInterval && refreshInterval > 0) 
	{
	   ts = Math.floor(ts / (refreshInterval * 1000));
	};
	if (url.indexOf("?") > -1) 
	{
	   sep = "&";
	};
	url = [ url, sep, "nocache=", ts ].join("");
	post_params();
	postdata={ osid:hostid , appid:appId , name:pname_arr[0] , imgurl:thumb_arr[0] , prourl:puid_url[0] , city:''};//ownercountry[0].fields_.locality };
	params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
	function pushdata_callback(response) 
	{        
		if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
		{
			pushOwnerData();
		}
		else
		{
			var res=eval('('+response.text+')');
			token=res.token;
		}
	}
	gadgets.io.makeRequest(url,pushdata_callback,params);
}
function getHtmlPage(pagename,dbhid,checkPast,f,actType)
{
	debug("getHtmlPage f="+f);
	if(typeof(f)=='undefined')
	{	
		if(document.getElementById('tab_load'))
		document.getElementById('tab_load').style.display="block";
	}
	else if(typeof(f)!='undefined' && f=='')
	{
		if(document.getElementById('tab_load'))
		document.getElementById('tab_load').style.display="block";
	}
	var refreshInterval=0;
	var err_cnt=0;
	u=0;
	var url="";
	if(prefs.getLang()=='pt')
	{
		url=appPageURL+'/prt_'+pagename+'.html';
	}
	else if(prefs.getLang()=='en')
	{
		url=appPageURL+'/eng_'+pagename+'.html';	
	}
	else
	{
		url=appPageURL+'/eng_'+pagename+'.html';
	}
	var ts = new Date().getTime();
	var sep = "?";
	if (refreshInterval && refreshInterval > 0) 
	{
	   ts = Math.floor(ts / (refreshInterval * 1000));
	};
	if (url.indexOf("?") > -1) 
	{
	   sep = "&";
	};
	url = [ url, sep, "nocache=", ts ].join("");
	function htmlpage_callback(response) 
	{     
		debug("typeof response.text="+typeof(response.text))
		debug("response.text="+response.text);
		debug("response.data="+response.data);
		debug("----------------------------------------------");
		if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
		{
			err_conunt++;
			if(err_conunt>4)
			{
				var message = Customized_ErrorMessages('servlet');
				 alert(message);
				 err_conunt=0;
				 return;
			}
			else
			{
				debug("new getHtmlPage("+pagename+","+dbhid+","+checkPast+", ,"+actType+")");
				getHtmlPage(pagename,dbhid,checkPast,'',actType);
			}
		}
		else
		{
			
			if(typeof(f)=='undefined')
			{
				if(document.getElementById('tab_load'))
				document.getElementById('tab_load').style.display="none";
			}
			else if(f=='yes')
			{
				pushOwnerData();
			}
			if(document.getElementById('app_main_canvas'))
			{
				document.getElementById('app_main_canvas').innerHTML = response.data;
				if(pagename=='hangout')
				{
					if(id_string.length>0)
					{
						clearArray(id_string);
					}
					id_string.length=0;
					param='schedule';
					document.getElementById('tab_hangout').className="selected";
					document.getElementById('tab_create').className="";
					document.getElementById('tab_past').className="";
					getHangouts('scheduled',1,1,f);
					getHangouts('new',1,1);
					adjustPageHeight();
				}
				else if(pagename=='create')
				{
					document.getElementById('tab_hangout').className="";
					document.getElementById('tab_create').className="selected";
					document.getElementById('tab_past').className="";
					//document.getElementById('tab_invite').className="";
					param="create";
					getCreateHangout();
					adjustPageHeight();
				}
				else if(pagename=='past')
				{
					if(id_string.length>0)
					{
						clearArray(id_string);
					}
					id_string.length=0;
					param="past";
					document.getElementById('tab_hangout').className="";
					document.getElementById('tab_create').className="";
					document.getElementById('tab_past').className="selected";
					getHangouts('past',1,1);
					getHangouts('friends',1,1);
					
					adjustPageHeight();
				}
				else if(pagename=='view')
				{
					if(id_string.length>0)
					{
						clearArray(id_string);
					}
					id_string.length=0;
					hid=dbhid;
					param='view';
					if(checkPast=="past")
					{
						document.getElementById('tab_hangout').className="";
						document.getElementById('tab_create').className="";
						document.getElementById('tab_past').className="selected";
					}
					else if(checkPast=="scheduled")
					{
						document.getElementById('tab_hangout').className="selected";
						document.getElementById('tab_create').className="";
						document.getElementById('tab_past').className="";
					}
					if(typeof(actType)!='undefined' && actType!='')
						viewdetails(hid,checkPast,actType);
					else
						viewdetails(hid,checkPast);
					adjustPageHeight();
				}
				else if(pagename=='edit')
				{
					document.getElementById('tab_hangout').className="selected";
					document.getElementById('tab_create').className="";
					document.getElementById('tab_past').className="";
					//document.getElementById('tab_invite').className="";
					param='edit';
					document.getElementById('edithtitle').value = jsonvar.Title;
					document.getElementById('editmessage').value = jsonvar.Description;
					document.getElementById('editvcity').value = jsonvar.city;
					document.getElementById('editvstreet').value = jsonvar.address2;
					document.getElementById('editvaddress1').value = jsonvar.address1;
					document.getElementById('btv').innerHTML='<a href="javascript:void(0);" onClick=getHtmlPage("view","'+jsonvar.HangoutID+'","scheduled") ><img src="'+appPageURL+'/images/back_arrow.gif" border=0 />&nbsp;'+displayMsg("btv")+'</a>';
					var when_st=jsonvar.StartTime;
					var where_st=when_st.split(' ');
					var when_end=jsonvar.EndTime;
					var where_end=when_end.split(' ');
					if(where_st[2]=="PM")
					{
						var time=where_st[1].split(':');
						if(time[0]=='08')
						{
							where_st[1] = '20:'+time[1];	
						}
						else if(time[0]=='09')
						{
							where_st[1] = '21:'+time[1];	
						}
						else if(time[0] == '12')
						{
							where_st[1] = '12:'+time[1];
						}
						else
						{
							where_st[1] = parseInt(time[0])+12+':'+time[1];
						}
					}
					if(where_end[2]=="PM")
					{
						var timeend=where_end[1].split(':');
						if(timeend[0]=='08')
						{
							where_end[1] = '20:'+timeend[1];
						}
						else if(timeend[0]=='09')
						{
							where_end[1] = '21:'+timeend[1];	
						}
						else if(timeend[0] == '12')
						{
							where_end[1] = '12:'+timeend[1];
						}
						else
						{
							where_end[1] = parseInt(timeend[0])+12+':'+timeend[1];
						}
					}
					document.getElementById('editsdate').value=where_st[0];
					document.getElementById('editstime').value=where_st[1];
					document.getElementById('editedate').value=where_end[0];
					document.getElementById('editetime').value=where_end[1];
					if(jsonvar.TypeID >0  &&  jsonvar.TypeID < 45) 
					{
						document.getElementById('editchar_other').style.display = 'none';
						document.getElementById('edithothertype').style.display = 'none';
						document.getElementById('edithothertype').value = '';
						document.getElementById('edithtype').value = jsonvar.TypeID;
					}
					else
					{
						document.getElementById('edithtype').value = 45;
						document.getElementById('editchar_other').style.display = 'block';
						document.getElementById('edithothertype').style.display = 'block';
						document.getElementById('edithothertype').value = jsonvar.TypeName;
					}
					selector();
					adjustPageHeight();
					
				}
				else if(pagename=='th_create')
				{
					param="th_create";
					document.getElementById('tab_hangout').className="";
					document.getElementById('tab_create').className="selected";
					document.getElementById('tab_past').className="";
					adjustPageHeight();
				}
				else if(pagename=='th_edit')
				{
					param="th_edit";
					document.getElementById('tab_hangout').className="";
					document.getElementById('tab_create').className="selected";
					document.getElementById('tab_past').className="";
					adjustPageHeight();
				}
				else if(pagename=='invite')
				{
					param="invite";
					document.getElementById('tab_hangout').className="";
					document.getElementById('tab_create').className="";
					document.getElementById('tab_past').className="";
					get_noapp_friends();
					adjustPageHeight();
				}
			}
		}
	};
	
	/*var params = {};
	var postdata={};
    params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
    params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.HTML;
   	params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);*/
	debug("url="+url);
	gadgets.io.makeRequest(url,htmlpage_callback);
	
}
function getHangouts(context,pageno,id,f)
{
	debug("getHangouts");
	if(id!=1)
	{
		document.getElementById('pg_loader_'+context).style.display='block';
	}
	html="";
	html_text="";
	if(typeof(f)!='undefined' && f=='yes')
	{
		flag=f;	
	}
	else
	{
		flag='no';		
	}
	var refreshInterval=0;
	if(cntr=='eng')
	{
		urlParams=['ctry=', 'US', '&lang=', 'en'];
	}
	else if(cntr=='prt')
	{
		urlParams=['ctry=', 'BR', '&lang=', 'pt'];	
	};
	var url=appServletURL+"/GetJSONHangouts?"+ urlParams.join('');
	var ts = new Date().getTime();
	var sep = "?";
	if (refreshInterval && refreshInterval > 0) 
	{
	   ts = Math.floor(ts / (refreshInterval * 1000));
	}
	if (url.indexOf("?") > -1) 
	{
	   sep = "&";
	}
	url = [ url, sep, "nocache=", ts ].join("");
	post_params();
	if(context=='showpast')
	{
		context='past';	
		postdata = {    hostid : hostid,    hcontext : context, recordno:10,pageno: pageno};
	}
	else if(currentview.getName()=='profile')
	{
		postdata = {    hostid : hostid,    hcontext : context, recordno:2,pageno: pageno};
	}
	else
	{
		postdata = {    hostid : hostid,    hcontext : context, recordno:5,pageno: pageno};
	}
	params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
	gadgets.io.makeRequest(url,callback,params);
	function callback(response) 
	{        
		if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null || response.errors[0]=="Error 400")
		{
			err_conunt++;
			if(err_conunt>4)
			{
				var message = Customized_ErrorMessages('servlet');
				 alert(message);
				 err_conunt=0;
				 return;
			}
			else
			{
				if(f=='showpastdata')
				{
					getHangouts('showpast',1,1,'showpastdata');
				}
				else
				{
					getHangouts(context,pageno,id);
				}
			}
		}
		else
		{
			p=5;
			
			if(context=='scheduled')
			{
				var sc_html="";
				var html_sch = eval('('+response.text+')');
				//_default_loc=html_sch.defaultlocation;
				/*if(typeof(html_sch.token)!='undefined' && html_sch.token!='')
				{
					token=html_sch.token;	
				}*/
				param='schedule';
				if((html_sch.totalhids%p)==0)
				{
					pages=parseInt(html_sch.totalhids/p);	
				}
				else
				{
					pages=parseInt(((html_sch.totalhids/p))+1);	
				}
				if(currentview.getName()=='canvas')
				{
					///canvas view
					if(html_sch.hangoutinfo.length!=0)
					{
						Pagination(pageno,id,context,pages);
						sc_html='<tr ><td><table cellspacing="0" cellpadding="0" border="0" width="795px"><tr ><td class="scheduletop"><table border="0" width="100%" cellspacing="0" cellpadding="0" align="center" valign="middle" ><tr><td style="padding-left:10px; font-size:11px" class="pageheading">'+displayMsg("Scheduled Hangouts")+'</td><td align="right"><span id="image_past" style="display:none"><img src="'+appPageURL+'/images/aj_loader.gif" border="0"/></span></td><td width="25px" align="right" style="padding-right:5px; font-size:10px; font-family: Verdana; font-weight:400; "></td><td align="right" style="padding-right:10px;font-size:10px; font-family: Verdana; font-weight:400">Page: '+pageno+'</td></tr></table></td></tr><tr class="schedulemiddle"><td width="795px"><table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" valign="top" ><tr><td height="8px"></td></tr>';
						for(var s=0;s<html_sch.hangoutinfo.length;s++)
						{
							if(html_sch.hangoutinfo[s].HostID[0].osid!='' && typeof(html_sch.hangoutinfo[s].HostID[0].osid) != 'undefined')
							{
								var hangout_creator = html_sch.hangoutinfo[s].HostID[0].osid;
								
								for(var i_index=0; puid_arr.length > i_index; i_index++)
								{
									if(hangout_creator == puid_arr[i_index])
									{
										host_thumb = thumb_arr[i_index];
										//host_url = domainURL+"/Profile.aspx?uid="+puid_url[i_index];
										host_url = unescape(puid_url[i_index]);
										host_name = pname_arr[i_index];
									};
								};
							};
							if(host_name == null)
							{
								if(html_sch.hangoutinfo[s].HostID[0].name != '' && typeof(html_sch.hangoutinfo[s].HostID[0].name) != 'undefined')
								{
								   host_thumb =  html_sch.hangoutinfo[s].HostID[0].imageURL;
								   host_url = unescape(html_sch.hangoutinfo[s].HostID[0].profileURL);
								   host_name = html_sch.hangoutinfo[s].HostID[0].name;
								}
								else
								{
									host_thumb = appPageURL+"/images/nophoto.gif";
									host_url = "javascript:void(0)";
									host_name = displayMsg("hostFriend");
								};
							};
							var	invited = getInvitedDetails(html_sch.hangoutinfo[s].HangoutID,html_sch.hangoutinfo[s].invitePerons,host_name,'scheduled');
							var accepted = getAcceptedDetails(html_sch.hangoutinfo[s].HangoutID,html_sch.hangoutinfo[s].acceptedPersons,host_name,'scheduled');
							if(html_sch.hangoutinfo[s].ActionType==0)
							{
								var zi=new Array();
								var za=new Array();
								for(var i_index=0; html_sch.hangoutinfo[s].invitePerons.length > i_index; i_index++)
								{
									zi[i_index] = html_sch.hangoutinfo[s].invitePerons[i_index].osid;
								};
								for(var i_index=0; html_sch.hangoutinfo[s].acceptedPersons.length > i_index; i_index++)
								{
									za[i_index] = html_sch.hangoutinfo[s].invitePerons[i_index].osid;
								};
								rsvp="<a id=cancel"+html_sch.hangoutinfo[s].HangoutID+"  href='javascript:void(0);' onclick=\"UpdateStatus(event,'cancel','"+html_sch.hangoutinfo[s].HangoutID+"','"+zi+"','"+za+"','"+escape(html_sch.hangoutinfo[s].Title)+"')\"><img src=\""+appPageURL+"/images/cancel.gif\" border=\"0\"> <u>"+displayMsg('Cancel')+"</u></a>";	
								if(puid_arr.length-1 == html_sch.hangoutinfo[s].invitePerons.length)
								{
									invitemore = "";
								}
								else
								{
									invitemore="<a href='javascript:void(0);' onclick=\"inviteMoreFriends('"+html_sch.hangoutinfo[s].HangoutID+"','"+html_sch.hangoutinfo[s].invitePerons[s]+"','morefriends')\"> <u>"+displayMsg('Invite More Friends')+"</u></a>";
								};
							} 
							else if(html_sch.hangoutinfo[s].ActionType==2)
							{
								rsvp='<span id="'+html_sch.hangoutinfo[s].HangoutID+'" onclick="show_responses(this.id)" style="cursor:pointer">'+displayMsg("Yes")+'</span>&nbsp;<img id="img_'+html_sch.hangoutinfo[s].HangoutID+'" src="'+appPageURL+'/images/dropdown_icon.gif" border="0" /><span id="responses_list_'+html_sch.hangoutinfo[s].HangoutID+'" style="display:none;z-index:2;border-width:0;"></span>';
								//rsvp="<a id=rsvp"+html_sch.hangoutinfo[s].HangoutID+"  href='javascript:void(0);' ondblclick=\"closewin('ddl_span"+html_sch.hangoutinfo[s].HangoutID+"')\" onclick=\"showme('"+html_sch.hangoutinfo[s].HangoutID+"')\"><span style='border:none' id=aa"+html_sch.hangoutinfo[s].HangoutID+" class='textbox'> "+displayMsg('Yes')+"  </span><img src='"+appPageURL+"/images/dropdown_icon.gif' border='0' /></a><span id=ddl_span"+html_sch.hangoutinfo[s].HangoutID+" style='display:none'><span id=htmlsel"+html_sch.hangoutinfo[s].HangoutID+"></span></span>";
								invitemore="";
							}
							else if(html_sch.hangoutinfo[s].ActionType==3)
							{
								rsvp='<span id="'+html_sch.hangoutinfo[s].HangoutID+'" onclick="show_responses(this.id)" style="cursor:pointer">'+displayMsg("May be")+'</span>&nbsp;<img id="img_'+html_sch.hangoutinfo[s].HangoutID+'" src="'+appPageURL+'/images/dropdown_icon.gif" border="0" /><span id="responses_list_'+html_sch.hangoutinfo[s].HangoutID+'" style="display:none;z-index:2;border-width:0;"></span>';
								//rsvp="<a id=rsvp"+html_sch.hangoutinfo[s].HangoutID+"  href='javascript:void(0);' ondblclick=\"closewin('ddl_span"+html_sch.hangoutinfo[s].HangoutID+"')\" onclick=\"showme('"+html_sch.hangoutinfo[s].HangoutID+"')\" ><span style='border:none' id=aa"+html_sch.hangoutinfo[s].HangoutID+" class='textbox'> "+displayMsg('May be')+"  </span><img src='"+appPageURL+"/images/dropdown_icon.gif' border='0' /> </a><span id=ddl_span"+html_sch.hangoutinfo[s].HangoutID+" style='display:none'><span id=htmlsel"+html_sch.hangoutinfo[s].HangoutID+"></span></span>";
								invitemore="";
							}
							if(hangout_creator==hostid)
							{
								sc_html+="<tr><td width='50px' align='center' valign='top' style='padding-left:5px'><img src='"+host_thumb+"' border='0' class='photoborder'><br><span style='font-size:9px; color:#747474'>"+host_name+"</span></td><td width='250px' valign='top' align='left'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_sch.hangoutinfo[s].HangoutID+"','scheduled','','"+html_sch.hangoutinfo[s].ActionType+"')>"+html_sch.hangoutinfo[s].StartDate+": "+html_sch.hangoutinfo[s].Title.substring(0,25)+"</a><br><span style='padding-left:15px;'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_sch.hangoutinfo[s].HangoutID+"','scheduled','','"+html_sch.hangoutinfo[s].ActionType+"') style='font-size:11px;color:#747474'>"+displayMsg('add / view photo video urls')+"</a></span></td><td width='175px' align='center' valign='top'><span id=rsvploading"+html_sch.hangoutinfo[s].HangoutID+" style='display:none'><img src='"+appPageURL+"/images/rsvp.gif'  border='0'/></span>"+rsvp+"</td><td width='220px' align='left' valign='top'  >"+displayMsg('Invitees')+": "+invited+"<br>"+displayMsg('Accepted')+": "+accepted+"<br></td></tr>";	
							}
							else
							{
								sc_html+="<tr><td width='50px' align='center' valign='top' style='padding-left:5px'><a href='"+host_url+"' target='_blank'><img src='"+host_thumb+"' border='0' class='photoborder'><br><span style='font-size:9px; color:#747474'>"+host_name+"</span></a></td><td width='250px' valign='top' align='left'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_sch.hangoutinfo[s].HangoutID+"','scheduled','','"+html_sch.hangoutinfo[s].ActionType+"')>"+html_sch.hangoutinfo[s].StartDate+": "+html_sch.hangoutinfo[s].Title.substring(0,25)+"</a><br><span style='padding-left:15px;'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_sch.hangoutinfo[s].HangoutID+"','scheduled','','"+html_sch.hangoutinfo[s].ActionType+"') style='font-size:11px;color:#747474'>"+displayMsg('add / view photo video urls')+"</a></span></td><td width='175px' align='center' valign='top'><span id=rsvploading"+html_sch.hangoutinfo[s].HangoutID+" style='display:none'><img src='"+appPageURL+"/images/rsvp.gif'  border='0'/></span>"+rsvp+"</td><td width='220px' align='left' valign='top'  >"+displayMsg('Invitees')+": "+invited+"<br>"+displayMsg('Accepted')+": "+accepted+"<br></td></tr>";	
							};	
						}
						sc_html+="<tr><td colspan='4' align='right'>"+paging+"</td></tr></table></td></tr><tr><td class='schedulebottom' height='11px' valign='top' align='center'></td></tr></table></td></tr></table></td></tr>";
						if(document.getElementById(context))
						{
							document.getElementById(context).innerHTML = sc_html;
							document.getElementById('pg_loader_'+context).style.display='none';
							if(pageno>1)
							{
								document.getElementById(context+'first').style.display='block';
								document.getElementById(context+'prev').style.display='block';
							}
							document.getElementById(context+pageno).style.fontSize="11px";
							document.getElementById(context+pageno).style.fontWeight="bold";
							document.getElementById(context+pageno).style.Color="#016497";
							document.getElementById(context+pageno).disabled=true;
						}
						adjustPageHeight();
					}
					else
					{
						sc_html='<tr ><td><table cellspacing="0" cellpadding="0" border="0" width="795px"><tr ><td class="scheduletop"><table border="0" width="100%" cellspacing="0" cellpadding="0" align="center" valign="middle" ><tr><td style="padding-left:10px; font-size:11px" class="pageheading">'+displayMsg("Scheduled Hangouts")+'</td><td align="right"><span id="image_past" style="display:none"><img src="'+appPageURL+'/images/aj_loader.gif" border="0"/></span></td><td width="25px" align="right" style="padding-right:5px; font-size:10px; font-family: Verdana; font-weight:400;"></td></tr></table></td></tr><tr class="noschedulemiddle"><td width="795px"><table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" valign="top" ><tr><td height="8px"></td></tr>';
				sc_html+="<tr><td>&nbsp;<br /><br /></td></tr><tr><td align='center' valing='middle' ><img src='"+appPageURL+"/images/profiletext.gif' border='0' /></td></tr><tr><td>&nbsp;</td></tr><tr><td align='center' valing='middle'><input type='button' id='btn_create' class='button' value='Create Hangout' name='B1' onclick=getHtmlPage('create','','') /><br /><br /><br /></td></tr></table></td></tr><tr><td class='noschedulebottom' height='11px' valign='top' align='center'></td></tr></table></td></tr></table></td></tr>";
						if(document.getElementById(context))
						{
							document.getElementById(context).innerHTML = sc_html;
						}
						adjustPageHeight();
					}
					//end of canvas view data
				}
				else
				{
					////profile view data
					if(html_sch.hangoutinfo.length!=0)
					{			
						sc_html='<tr ><td><table cellspacing="0" cellpadding="0" border="0" width="490px"><tr ><td class="profilebgtop" height="25px"><table border="0" cellspacing="0" cellpadding="0" align="center" valign="middle" width="100%" ><tr><td style="padding-left:10px; font-size:11px" class="pageheading" align="left" >'+displayMsg("Scheduled Hangouts")+'</td></tr></table></td></tr><tr class="profilebgmiddle"><td><table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" valign="top" ><tr><td height="8px"></td></tr>';
						for(var i=0;i<html_sch.hangoutinfo.length;i++)
						{
							var hostdata=GetFriendDataById(html_sch.hangoutinfo[i].HostID);									
							var	invited = getInvitedDetails(html_sch.hangoutinfo[i].HangoutID,html_sch.hangoutinfo[i].invitePerons,host_name,'scheduled');
							var accepted = getAcceptedDetails(html_sch.hangoutinfo[i].HangoutID,html_sch.hangoutinfo[i].acceptedPersons,host_name,'scheduled');
							invitemore="";
							if(html_sch.hangoutinfo[i].ActionType==0)
							{
								if(puid_arr.length-1 == html_sch.hangoutinfo[i].invitePerons.length)
								{
									invitemore= "";
								}
								else
								{
									invitemore="<a href='javascript:void(0);' onclick='gotoCanvas()'> <u>"+displayMsg('Invite More Friends')+"</u></a>";
								}
							}
							else if(html_sch.hangoutinfo[i].ActionType==2)
							{									
								invitemore="";
							}
							else if(html_sch.hangoutinfo[i].ActionType==3)
							{									
								invitemore="";
							}								
							var host_thumb='',host_url='',host_name=null;
							var hangout_creator = html_sch.hangoutinfo[i].HostID[0].osid;
							for(var i_index=0; puid_arr.length > i_index; i_index++)
							{
								if(hangout_creator == puid_arr[i_index])
								{
									host_thumb = thumb_arr[i_index];
									//host_url = domainURL+"/Profile.aspx?uid="+puid_url[i_index];
									host_url = unescape(puid_url[i_index]);
									host_name = pname_arr[i_index];
								}
							}
							if(host_name == null)
							{
								if(html_sch.hangoutinfo[i].HostID[0].name != '' && typeof(html_sch.hangoutinfo[i].HostID[0].name) != 'undefined')
								{
								   host_thumb =  html_sch.hangoutinfo[i].HostID[0].imageURL;
								   host_url = unescape(html_sch.hangoutinfo[i].HostID[0].profileURL);
								   host_name = html_sch.hangoutinfo[i].HostID[0].name;
								}
								else
								{
									host_thumb = appPageURL+"/images/nophoto.gif";
									host_url = "javascript:void(0)";
									host_name = displayMsg("hostFriend");
								}
							}
							sc_html+="<tr><td align='center' valign='top' style='padding-left:5px' width='10%'><a href='javascript:void(0);'><img src='"+host_thumb+"' border='0' class='photoborder'><br><span style='font-size:9px; color:#747474'>"+host_name+"</span></a></td><td valign='top' align='left'><a href='javascript:void(0);' onclick='gotoCanvas()'>"+html_sch.hangoutinfo[i].StartDate+": "+html_sch.hangoutinfo[i].Title.substring(0,25)+"</a></td><td align='center' valign='top'></td><td align='left' valign='top'  >"+displayMsg('Invitees')+": "+invited+"<br>"+displayMsg('Accepted')+": "+accepted+"<br></td></tr>";
						}
					}
					else
					/*{
						sc_html='<tr ><td><table cellspacing="0" cellpadding="0" border="0" width="490px"><tr class="profilebg"><td width="490px"><table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" valign="top" ><tr><td height="8px"></td></tr>';
						sc_html+="<tr><td align='center' valing='middle' height='50px'><span class='pageheading' style='font-size:13px'> "+displayMsg("noSHangouts")+" <br><br><br></span><input type='button' id='btn_create' class='button' value='Create Hangout' name='B1' onclick=getHtmlPage('create','','') /><br><br><br><br></td></tr>";
					}*/
					{
						sc_html='<tr ><td><table cellspacing="0" cellpadding="0" border="0" width="490px"><tr ><td class="profilebgtop" height="25px"><table border="0" cellspacing="0" cellpadding="0" align="center" valign="middle" width="100%" ><tr><td style="padding-left:10px; font-size:11px" class="pageheading" align="left" >'+displayMsg("Scheduled Hangouts")+'</td></tr></table></td></tr><tr class="profilebgmiddle"><td width="490px" height="182px"><table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" valign="top" ><tr><td height="8px"></td></tr>';
						sc_html+="<tr><td align='center' valing='middle' ><img src='"+appPageURL+"/images/profiletext.gif' border='0' /></td></tr><tr><td>&nbsp;</td></tr><tr><td align='center' valing='middle' ><input type='button' id='btn_create' class='button' value='Create Hangout' name='B1' onclick=getHtmlPage('create','','') /></td></tr>";
					}
					
					sc_html+="</table></td></tr><tr><td class='profilebgbottom' height='11px' valign='top' align='center'></td></tr><tr><td align='right' valign='bottom' style='color:#747474; font-size:10px; padding-right:5px'>by <a href='http://www.auciti.com' target='_blank' style='color:#747474'>auciti.com</a> | <a target='_blank' href='http://www.orkut.com/Community.aspx?cmm=47593020'>Discussion and Feedback</a></td></tr>";
					if(document.getElementById('profile_scheduled'))
					document.getElementById('profile_scheduled').innerHTML = sc_html;
					//end of profile view data
				}
				
			}
			else if(context=='new')
			{
				var html_new = eval('('+response.text+')');
				if((html_new.totalhids%p)==0)
				{
					pages=parseInt(html_new.totalhids/p);	
				}
				else
				{
					pages=parseInt(((html_new.totalhids/p))+1);	
				}
				var new_html="";
				if(html_new.hangoutinfo.length!=0)
				{	
					Pagination(pageno,id,context,pages);
					new_html='<tr ><td><table cellspacing="0" cellpadding="0" border="0" width="795px"><tr ><td class="scheduletop"><table border="0" width="100%" cellspacing="0" cellpadding="0" align="center" valign="middle" ><tr><td style="padding-left:10px; font-size:11px" class="pageheading">'+displayMsg("New Requests")+'</td><td align="right"><span id="image_sch" style="display:none"><img src="'+appPageURL+'/images/aj_loader.gif" border="0"/></span></td><td width="25px" align="right" style="padding-right:5px; font-size:10px; font-family: Verdana; font-weight:400; "></td><td align="right" style="padding-right:10px;font-size:10px; font-family: Verdana; font-weight:400">Page: '+pageno+'</td></tr></table></td></tr><tr class="schedulemiddle"><td width="795px"><table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" valign="top" ><tr><td height="8px"></td></tr>';
					for(var s=0;s<html_new.hangoutinfo.length;s++)
					{
						if(html_new.hangoutinfo[s].HostID[0].osid!='' && typeof(html_new.hangoutinfo[s].HostID[0].osid) != 'undefined')
						{
							var hangout_creator = html_new.hangoutinfo[s].HostID[0].osid;
							
							for(var i_index=0; puid_arr.length > i_index; i_index++)
							{
								if(hangout_creator == puid_arr[i_index])
								{
									host_thumb = thumb_arr[i_index];
									//host_url = domainURL+"/Profile.aspx?uid="+puid_url[i_index];
									host_url = unescape(puid_url[i_index]);
									host_name = pname_arr[i_index];
								};
							};
						};
						if(host_name == null)
						{
							if(html_new.hangoutinfo[s].HostID[0].name != '' && typeof(html_new.hangoutinfo[s].HostID[0].name) != 'undefined')
							{
							   host_thumb =  html_new.hangoutinfo[s].HostID[0].imageURL;
							   host_url = unescape(html_new.hangoutinfo[s].HostID[0].profileURL);
							   host_name = html_new.hangoutinfo[s].HostID[0].name;
							}
							else
							{
								host_thumb = appPageURL+"/images/nophoto.gif";
								host_url = "javascript:void(0)";
								host_name = displayMsg("hostFriend");
							};
						};
						var	invited = getInvitedDetails(html_new.hangoutinfo[s].HangoutID,html_new.hangoutinfo[s].invitePerons,host_name,'scheduled');
						var accepted = getAcceptedDetails(html_new.hangoutinfo[s].HangoutID,html_new.hangoutinfo[s].acceptedPersons,host_name,'scheduled');
						if(html_new.hangoutinfo[s].ActionType==0)
						{
							var zi=new Array();
							var za=new Array();
							for(var i_index=0; html_new.hangoutinfo[s].invitePerons.length > i_index; i_index++)
							{
								zi[i_index] = html_new.hangoutinfo[s].invitePerons[i_index].osid;
							};
							for(var i_index=0; html_new.hangoutinfo[s].acceptedPersons.length > i_index; i_index++)
							{
								za[i_index] = html_new.hangoutinfo[s].invitePerons[i_index].osid;
							};
							rsvp="<a id=cancel"+html_new.hangoutinfo[s].HangoutID+"  href='javascript:void(0);' onclick=\"UpdateStatus(event,'cancel','"+html_new.hangoutinfo[s].HangoutID+"','"+zi+"','"+za+"','"+escape(html_new.hangoutinfo[s].Title)+"')\"><img src=\""+appPageURL+"/images/cancel.gif\" border=\"0\"> <u>"+displayMsg('Cancel')+"</u></a>";	
							if(puid_arr.length-1 == html_new.hangoutinfo[s].invitePerons.length)
							{
								invitemore = "";
							}
							else
							{
								invitemore="<a href='javascript:void(0);' onclick=\"inviteMoreFriends('"+html_new.hangoutinfo[s].HangoutID+"','"+html_new.hangoutinfo[s].invitePerons[s]+"','morefriends')\"> <u>"+displayMsg('Invite More Friends')+"</u></a>";
							};
						} 
						else if(html_new.hangoutinfo[s].ActionType==1)
						{
							rsvp='<span id="'+html_new.hangoutinfo[s].HangoutID+'" onclick="show_responses(this.id)" style="cursor:pointer">'+displayMsg("Invited")+'</span>&nbsp;<img  id="img_'+html_new.hangoutinfo[s].HangoutID+'" src="'+appPageURL+'/images/dropdown_icon.gif" border="0" /><span id="responses_list_'+html_new.hangoutinfo[s].HangoutID+'" style="display:none;z-index:2;border-width:0;"></span>';
								//rsvp="<a id=rsvp"+html_new.hangoutinfo[s].HangoutID+"  href='javascript:void(0);' ondblclick=\"closewin('ddl_span"+html_new.hangoutinfo[s].HangoutID+"')\" onclick=\"showme('"+html_new.hangoutinfo[s].HangoutID+"')\"><span style='border:none' id=aa"+html_new.hangoutinfo[s].HangoutID+" class='textbox'>"+displayMsg('Invited')+"  </span><img src='"+appPageURL+"/images/dropdown_icon.gif' border='0' /></a><span id=ddl_span"+html_new.hangoutinfo[s].HangoutID+" style='display:none'><span id=htmlsel"+html_new.hangoutinfo[s].HangoutID+"></span></span>";
							invitemore="";
						}
						else if(html_new.hangoutinfo[s].ActionType==4)
						{
							rsvp='<span id="'+html_new.hangoutinfo[s].HangoutID+'" onclick="show_responses(this.id)" style="cursor:pointer">'+displayMsg("No")+'</span>&nbsp;<img id="img_'+html_new.hangoutinfo[s].HangoutID+'" src="'+appPageURL+'/images/dropdown_icon.gif" border="0" /><span id="responses_list_'+html_new.hangoutinfo[s].HangoutID+'" style="display:none;z-index:2;border-width:0;"></span>';
								//rsvp="<a id=rsvp"+html_new.hangoutinfo[s].HangoutID+"  href='javascript:void(0);' ondblclick=\"closewin('ddl_span"+html_new.hangoutinfo[s].HangoutID+"')\" onclick=\"showme('"+html_new.hangoutinfo[s].HangoutID+"')\"><span style='border:none' id=aa"+html_new.hangoutinfo[s].HangoutID+" class='textbox'>"+displayMsg('No')+" </span><img src='"+appPageURL+"/images/dropdown_icon.gif' border='0' /></a><span id=ddl_span"+html_new.hangoutinfo[s].HangoutID+" style='display:none'><span id=htmlsel"+html_new.hangoutinfo[s].HangoutID+"></span></span>";
								invitemore="";
						};
						if(hangout_creator==hostid)
						{
							new_html+="<tr><td width='50px' align='center' valign='top' style='padding-left:5px'><img src='"+host_thumb+"' border='0' class='photoborder'><br><span style='font-size:9px; color:#747474'>"+host_name+"</span></td><td width='250px' valign='top' align='left'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_new.hangoutinfo[s].HangoutID+"','scheduled','','"+html_new.hangoutinfo[s].ActionType+"')>"+html_new.hangoutinfo[s].StartDate+": "+html_new.hangoutinfo[s].Title.substring(0,25)+"</a><br><span style='padding-left:15px;'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_new.hangoutinfo[s].HangoutID+"','scheduled','','"+html_new.hangoutinfo[s].ActionType+"') style='font-size:11px;color:#747474'>"+displayMsg('add / view photo video urls')+"</a></span></td><td width='175px' align='center' valign='top'><span id=rsvploading"+html_new.hangoutinfo[s].HangoutID+" style='display:none'><img src='"+appPageURL+"/images/rsvp.gif'  border='0'/></span>"+rsvp+"</td><td width='220px' align='left' valign='top'  >"+displayMsg('Invitees')+": "+invited+"<br>"+displayMsg('Accepted')+": "+accepted+"<br></td></tr>";	
						}
						else
						{
							new_html+="<tr><td width='50px' align='center' valign='top' style='padding-left:5px'><a href='"+host_url+"' target='_blank'><img src='"+host_thumb+"' border='0' class='photoborder'><br><span style='font-size:9px; color:#747474'>"+host_name+"</span></a></td><td width='250px' valign='top' align='left'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_new.hangoutinfo[s].HangoutID+"','scheduled','','"+html_new.hangoutinfo[s].ActionType+"')>"+html_new.hangoutinfo[s].StartDate+": "+html_new.hangoutinfo[s].Title.substring(0,25)+"</a><br><span style='padding-left:15px;'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_new.hangoutinfo[s].HangoutID+"','scheduled','','"+html_new.hangoutinfo[s].ActionType+"') style='font-size:11px;color:#747474'>"+displayMsg('add / view photo video urls')+"</a></span></td><td width='175px' align='center' valign='top'><span id=rsvploading"+html_new.hangoutinfo[s].HangoutID+" style='display:none'><img src='"+appPageURL+"/images/rsvp.gif'  border='0'/></span>"+rsvp+"</td><td width='220px' align='left' valign='top'  >"+displayMsg('Invitees')+": "+invited+"<br>"+displayMsg('Accepted')+": "+accepted+"<br></td></tr>";	
						};	
					}
					new_html+="<tr><td colspan='4' align='right'>"+paging+"</td></tr></table></td></tr><tr><td class='schedulebottom' height='11px' valign='top' align='center'></td></tr></table></td></tr>";
					if(document.getElementById('newrequests'))
					{
						document.getElementById('newrequests').innerHTML = new_html;
						document.getElementById('pg_loader_'+context).style.display='none';
						if(pageno>1)
						{
							document.getElementById(context+'first').style.display='block';
							document.getElementById(context+'prev').style.display='block';
						}
						else if(pageno==1)
						{
								
						}
						document.getElementById(context+pageno).style.fontSize="11px";						
						document.getElementById(context+pageno).style.fontWeight="bold";
						document.getElementById(context+pageno).style.Color="#016497";
						document.getElementById(context+pageno).disabled=true;
					}
					adjustPageHeight();

				}
				else
				{
					new_html='<tr ><td><table cellspacing="0" cellpadding="0" border="0" width="795px"><tr ><td class="scheduletop"><table border="0" width="100%" cellspacing="0" cellpadding="0" align="center" valign="middle" ><tr><td style="padding-left:10px; font-size:11px" class="pageheading">'+displayMsg("New Requests")+'</td><td align="right"><span id="image_past" style="display:none"><img src="'+appPageURL+'/images/aj_loader.gif" border="0"/></span></td><td width="25px" align="right" style="padding-right:5px; font-size:10px; font-family: Verdana; font-weight:400; "></td></tr></table></td></tr><tr class="noschedulemiddle"><td width="795px"><table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" valign="top" ><tr><td height="8px"></td></tr>';
				new_html+="<tr><td>&nbsp;<br /><br /></td></tr><tr><td align='center' valing='middle' ><img src='"+appPageURL+"/images/newrequesttext.gif' border='0' /></td></tr><tr><td>&nbsp;</td></tr><tr><td align='center' valing='middle'><input type='button' id='btn_create' class='button' value='Create Hangout' name='B1' onclick=getHtmlPage('create','','') /><br /><br /><br /></td></tr></table></td></tr><tr><td class='noschedulebottom' height='11px' valign='top' align='center'></td></tr></table></td></tr>";
					if(document.getElementById('newrequests'))
					document.getElementById('newrequests').innerHTML = new_html;
					adjustPageHeight();
				}
			}
			else if(context=='past')
			{
				var html_past = eval('('+response.text+')');
				if((html_past.totalhids%10)==0)
				{
					pages=parseInt(html_past.totalhids/10);	
				}
				else
				{
					pages=parseInt(((html_past.totalhids/10))+1);	
				}
				
				if(f=='showpastdata')
				{
					if(html_past.hangoutinfo.length!=0)
					{
						Pagination(pageno,id,'showpast',pages);
						document.getElementById('sample').style.display='block';
						var showpast_html='<table cellpadding="0" cellspacing="0" border="0"  width="100%"><tr class="altrow1"><td width="200" align="left" class="showpast">Title</td><td width="100" align="left" class="showpast">Type</td><td width="225" align="left" class="showpast">Location</td><td width="70" align="left" class="showpast">Start Time</td></tr>';
						if((html_past.totalhids%p)==0)
						{
							pages=parseInt(html_past.totalhids/p);	
						}
						else
						{
							pages=parseInt(((html_past.totalhids/p))+1);	
						}
						if(html_past.hangoutinfo.length!=0)
						{
							for(var s=0;s<html_past.hangoutinfo.length;s++)
							{
								var cls="";
								if(s%2==0)
								{
									cls="altrow";
								}
								else
								{
									cls="altrow1";
								}	

								if(html_past.hangoutinfo[s].Location[0].Address2!='' && typeof(html_past.hangoutinfo[s].Location[0].Address2)!='undefined')
								{
									showpast_html+="<tr class='"+cls+"'><td align='left' class='checkpast01' valign='top'><a href='javascript:void(0);' onclick=populate('"+escape(html_past.hangoutinfo[s].Title)+"','"+html_past.hangoutinfo[s].TypeID+"','"+escape(html_past.hangoutinfo[s].TypeName)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address1)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address2)+"','"+escape(html_past.hangoutinfo[s].Location[0].city)+"','"+escape(html_past.hangoutinfo[s].Description)+"','','pastdata')>"+html_past.hangoutinfo[s].Title.substring(0,35)+"</a></td><td><a href='javascript:void(0);' onclick=populate('"+escape(html_past.hangoutinfo[s].Title)+"','"+html_past.hangoutinfo[s].TypeID+"','"+escape(html_past.hangoutinfo[s].TypeName)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address1)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address2)+"','"+escape(html_past.hangoutinfo[s].Location[0].city)+"','"+escape(html_past.hangoutinfo[s].Description)+"','','pastdata')>"+html_past.hangoutinfo[s].TypeName+"</a></td><td align='left' class='checkpast' valign='top'><a href='javascript:void(0);' onclick=populate('"+escape(html_past.hangoutinfo[s].Title)+"','"+html_past.hangoutinfo[s].TypeID+"','"+escape(html_past.hangoutinfo[s].TypeName)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address1)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address2)+"','"+escape(html_past.hangoutinfo[s].Location[0].city)+"','"+escape(html_past.hangoutinfo[s].Description)+"','','pastdata')>"+html_past.hangoutinfo[s].Location[0].Address1.substring(0,18)+", "+html_past.hangoutinfo[s].Location[0].Address2.substring(0,18)+", "+html_past.hangoutinfo[s].Location[0].city.substring(0,18)+"</a></td><td><a href='javascript:void(0);' onclick=populate('"+escape(html_past.hangoutinfo[s].Title)+"','"+html_past.hangoutinfo[s].TypeID+"','"+escape(html_past.hangoutinfo[s].TypeName)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address1)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address2)+"','"+escape(html_past.hangoutinfo[s].Location[0].city)+"','"+escape(html_past.hangoutinfo[s].Description)+"','','pastdata')>"+html_past.hangoutinfo[s].StartDate+"</a></td></tr>";		
								}
								else
								{
									showpast_html+="<tr class='"+cls+"'><td align='left' class='checkpast01' valign='top'><a href='javascript:void(0);' onclick=populate('"+escape(html_past.hangoutinfo[s].Title)+"','"+html_past.hangoutinfo[s].TypeID+"','"+escape(html_past.hangoutinfo[s].TypeName)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address1)+"','','"+escape(html_past.hangoutinfo[s].Location[0].city)+"','"+escape(html_past.hangoutinfo[s].Description)+"','','pastdata')>"+html_past.hangoutinfo[s].Title.substring(0,35)+"</a></td><td><a href='javascript:void(0);' onclick=populate('"+escape(html_past.hangoutinfo[s].Title)+"','"+html_past.hangoutinfo[s].TypeID+"','"+escape(html_past.hangoutinfo[s].TypeName)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address1)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address2)+"','"+escape(html_past.hangoutinfo[s].Location[0].city)+"','"+escape(html_past.hangoutinfo[s].Description)+"','','pastdata')>"+html_past.hangoutinfo[s].TypeName+"</a></td><td align='left' class='checkpast' valign='top'><a href='javascript:void(0);' onclick=populate('"+escape(html_past.hangoutinfo[s].Title)+"','"+html_past.hangoutinfo[s].TypeID+"','"+escape(html_past.hangoutinfo[s].TypeName)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address1)+"','','"+escape(html_past.hangoutinfo[s].Location[0].city)+"','"+escape(html_past.hangoutinfo[s].Description)+"','','pastdata')>"+html_past.hangoutinfo[s].Location[0].Address1.substring(0,25)+", "+html_past.hangoutinfo[s].Location[0].city.substring(0,25)+"</a></td><td><a href='javascript:void(0);' onclick=populate('"+escape(html_past.hangoutinfo[s].Title)+"','"+html_past.hangoutinfo[s].TypeID+"','"+escape(html_past.hangoutinfo[s].TypeName)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address1)+"','"+escape(html_past.hangoutinfo[s].Location[0].Address2)+"','"+escape(html_past.hangoutinfo[s].Location[0].city)+"','"+html_past.hangoutinfo[s].Description+"','','pastdata')>"+escape(html_past.hangoutinfo[s].StartDate)+"</a></td></tr>";	
								}
							}
							showpast_html+="<tr><td colspan='4' align='right'>"+paging+"</td></tr></table>";
							if(document.getElementById('getHangouts'))
							{
								document.getElementById('getHangouts').style.display='block';
								document.getElementById('showpast').innerHTML = showpast_html;
								document.getElementById('pg_loader_showpast').style.display='none';
								if(pageno>1)
								{
									document.getElementById('showpastfirst').style.display='block';
									document.getElementById('showpastprev').style.display='block';
								}
								document.getElementById('showpast'+pageno).style.fontSize="11px";
								document.getElementById('showpast'+pageno).style.fontWeight="bold";								
								document.getElementById('showpast'+pageno).style.Color="#016497";
								document.getElementById('showpast'+pageno).disabled=true;
							}
							adjustPageHeight();
						}
					}
					else
					{
						alert("No Past Hangouts.");	
					}
				}
				else
				{
					var past_html="";
					
					if(html_past.hangoutinfo.length!=0)
					{
						Pagination(pageno,id,context,pages);
						past_html='<tr ><td><table cellspacing="0" cellpadding="0" border="0" width="795px"><tr ><td class="scheduletop"><table border="0" width="100%" cellspacing="0" cellpadding="0" align="center" valign="middle" ><tr><td style="padding-left:10px; font-size:11px" class="pageheading">'+displayMsg("My Past Hangouts")+'</td><td align="right"><span id="image_past" style="display:none"><img src="'+appPageURL+'/images/aj_loader.gif" border="0"/></span></td><td width="25px" align="right" style="padding-right:5px; font-size:10px; font-family: Verdana; font-weight:400; "></td><td align="right" style="padding-right:10px;font-size:10px; font-family: Verdana; font-weight:400">Page: '+pageno+'</td></tr></table></td></tr><tr class="schedulemiddle"><td width="795px"><table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" valign="top" ><tr><td height="8px"></td></tr>';
						for(var s=0;s<html_past.hangoutinfo.length;s++)
						{
							if(html_past.hangoutinfo[s].HostID[0].osid!='' && typeof(html_past.hangoutinfo[s].HostID[0].osid) != 'undefined')
							{
								var hangout_creator = html_past.hangoutinfo[s].HostID[0].osid;
								
								for(var i_index=0; puid_arr.length > i_index; i_index++)
								{
									if(hangout_creator == puid_arr[i_index])
									{
										host_thumb = thumb_arr[i_index];
										//host_url = domainURL+"/Profile.aspx?uid="+puid_url[i_index];
										host_url = unescape(puid_url[i_index]);
										host_name = pname_arr[i_index];
									};
								};
							};
							if(host_name == null)
							{
								if(html_past.hangoutinfo[s].HostID[0].name != '' && typeof(html_past.hangoutinfo[s].HostID[0].name) != 'undefined')
								{
								   host_thumb =  html_past.hangoutinfo[s].HostID[0].imageURL;
								   host_url = unescape(html_past.hangoutinfo[s].HostID[0].profileURL);
								   host_name = html_past.hangoutinfo[s].HostID[0].name;
								}
								else
								{
									host_thumb = appPageURL+"/images/nophoto.gif";
									host_url = "javascript:void(0)";
									host_name = displayMsg("hostFriend");
								};
							};
							var	invited = getInvitedDetails(html_past.hangoutinfo[s].HangoutID,html_past.hangoutinfo[s].invitePerons,host_name,'past');
							var accepted = getAcceptedDetails(html_past.hangoutinfo[s].HangoutID,html_past.hangoutinfo[s].acceptedPersons,host_name,'past');
							
							if(hangout_creator==hostid)
							{
								past_html+="<tr><td width='50px' align='center' valign='top' style='padding-left:5px'><img src='"+host_thumb+"' border='0' class='photoborder'><br><span style='font-size:9px; color:#747474'>"+host_name+"</span></td><td width='250px' valign='top' align='left'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_past.hangoutinfo[s].HangoutID+"','past','','"+html_past.hangoutinfo[s].ActionType+"')>"+html_past.hangoutinfo[s].StartDate+": "+html_past.hangoutinfo[s].Title.substring(0,25)+"</a><br><span style='padding-left:15px;'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_past.hangoutinfo[s].HangoutID+"','past','','"+html_past.hangoutinfo[s].ActionType+"') style='font-size:11px;color:#747474'>"+displayMsg('add / view photo video urls')+"</a></span></td><td width='175px' align='center' valign='top'><span id=rsvploading"+html_past.hangoutinfo[s].HangoutID+" style='display:none'><img src='"+appPageURL+"/images/rsvp.gif'  border='0'/></span></td><td width='220px' align='left' valign='top'  >"+displayMsg('Invitees')+": "+invited+"<br>"+displayMsg('Accepted')+": "+accepted+"<br></td></tr>";	
							}
							else
							{
								past_html+="<tr><td width='50px' align='center' valign='top' style='padding-left:5px'><a href='"+host_url+"' target='_blank'><img src='"+host_thumb+"' border='0' class='photoborder'><br><span style='font-size:9px; color:#747474'>"+host_name+"</span></a></td><td width='250px' valign='top' align='left'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_past.hangoutinfo[s].HangoutID+"','past','','"+html_past.hangoutinfo[s].ActionType+"')>"+html_past.hangoutinfo[s].StartDate+": "+html_past.hangoutinfo[s].Title.substring(0,25)+"</a><br><span style='padding-left:15px;'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_past.hangoutinfo[s].HangoutID+"','past','','"+html_past.hangoutinfo[s].ActionType+"') style='font-size:11px;color:#747474'>"+displayMsg('add / view photo video urls')+"</a></span></td><td width='175px' align='center' valign='top'><span id=rsvploading"+html_past.hangoutinfo[s].HangoutID+" style='display:none'><img src='"+appPageURL+"/images/rsvp.gif'  border='0'/></span></td><td width='220px' align='left' valign='top'  >"+displayMsg('Invitees')+": "+invited+"<br>"+displayMsg('Accepted')+": "+accepted+"<br></td></tr>";	
							};	
						}
						past_html+="<tr><td colspan='4' align='right'>"+paging+"</td></tr></table></td></tr><tr><td class='schedulebottom' height='11px' valign='top' align='center'></td></tr></table></td></tr></table></td></tr>";
						if(document.getElementById(context))
						{
							document.getElementById(context).innerHTML = past_html;
							document.getElementById('pg_loader_'+context).style.display='none';
							if(pageno>1)
							{
								document.getElementById(context+'first').style.display='block';
								document.getElementById(context+'prev').style.display='block';
							}
							document.getElementById(context+pageno).style.fontSize="11px";						
							document.getElementById(context+pageno).style.fontWeight="bold";
							document.getElementById(context+pageno).style.Color="#016497";
							document.getElementById(context+pageno).disabled=true;
						}
						adjustPageHeight();
					}
					else
					{
						past_html='<tr ><td><table cellspacing="0" cellpadding="0" border="0" width="795px"><tr ><td class="scheduletop"><table border="0" width="100%" cellspacing="0" cellpadding="0" align="center" valign="middle" ><tr><td style="padding-left:10px; font-size:11px" class="pageheading">'+displayMsg("My Past Hangouts")+'</td><td align="right"><span id="image_past" style="display:none"><img src="'+appPageURL+'/images/aj_loader.gif" border="0"/></span></td><td width="25px" align="right" style="padding-right:5px; font-size:10px; font-family: Verdana; font-weight:400; "></td></tr></table></td></tr><tr class="noschedulemiddle"><td width="795px"><table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" valign="top" ><tr><td height="8px"></td></tr>';
					past_html+="<tr><td>&nbsp;<br /><br /></td></tr><tr><td align='center' valing='middle' ><img src='"+appPageURL+"/images/nopasthangouts.gif' border='0' /></td></tr><tr><td>&nbsp;</td></tr><tr><td align='center' valing='middle'><input type='button' id='btn_create' class='button' value='Create Hangout' name='B1' onclick=getHtmlPage('create','','') /><br /><br /><br /></td></tr></table></td></tr><tr><td class='noschedulebottom' height='11px' valign='top' align='center'></td></tr></table></td></tr>";
					
					if(document.getElementById(context))
						document.getElementById(context).innerHTML = past_html;
						adjustPageHeight();
					}
				}
			}
			else if(context=='friends')
			{
				var friends_html="";
				var html_friends=eval('('+response.text+')');
				if((html_friends.totalhids%p)==0)
				{
					pages=parseInt(html_friends.totalhids/p);	
				}
				else
				{
					pages=parseInt(((html_friends.totalhids/p))+1);	
				}
				if(html_friends.hangoutinfo.length!=0)
				{						
					Pagination(pageno,id,context,pages);
					friends_html='<tr ><td><table cellspacing="0" cellpadding="0" border="0" width="795px"><tr ><td class="scheduletop"><table border="0" width="100%" cellspacing="0" cellpadding="0" align="center" valign="middle" ><tr><td style="padding-left:10px; font-size:11px" class="pageheading">'+displayMsg("Friends Hangouts")+'</td><td align="right"><span id="image_past" style="display:none"><img src="'+appPageURL+'/images/aj_loader.gif" border="0"/></span></td><td width="25px" align="right" style="padding-right:5px; font-size:10px; font-family: Verdana; font-weight:400; "></td><td align="right" style="padding-right:10px;font-size:10px; font-family: Verdana; font-weight:400">Page: '+pageno+'</td></tr></table></td></tr><tr class="schedulemiddle"><td width="795px"><table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" valign="top" ><tr><td height="8px"></td></tr>';
					for(var s=0;s<html_friends.hangoutinfo.length;s++)
					{
						if(html_friends.hangoutinfo[s].HostID[0].osid!='' && typeof(html_friends.hangoutinfo[s].HostID[0].osid) != 'undefined')
						{
							var hangout_creator = html_friends.hangoutinfo[s].HostID[0].osid;
							
							for(var i_index=0; puid_arr.length > i_index; i_index++)
							{
								if(hangout_creator == puid_arr[i_index])
								{
									host_thumb = thumb_arr[i_index];
									//host_url = domainURL+"/Profile.aspx?uid="+puid_url[i_index];
									host_url = unescape(puid_url[i_index]);
									host_name = pname_arr[i_index];
								};
							};
						};
						if(host_name == null)
						{
							if(html_friends.hangoutinfo[s].HostID[0].name != '' && typeof(html_friends.hangoutinfo[s].HostID[0].name) != 'undefined')
							{
							   host_thumb =  html_friends.hangoutinfo[s].HostID[0].imageURL;
							   host_url = unescape(html_friends.hangoutinfo[s].HostID[0].profileURL);
							   host_name = html_friends.hangoutinfo[s].HostID[0].name;
							}
							else
							{
								host_thumb = appPageURL+"/images/nophoto.gif";
								host_url = "javascript:void(0)";
								host_name = displayMsg("hostFriend");
							};
						};
						var	invited = getInvitedDetails(html_friends.hangoutinfo[s].HangoutID,html_friends.hangoutinfo[s].invitePerons,host_name,'past');
						var accepted = getAcceptedDetails(html_friends.hangoutinfo[s].HangoutID,html_friends.hangoutinfo[s].acceptedPersons,host_name,'past');
						
						if(hangout_creator==hostid)
						{
							friends_html+="<tr><td width='50px' align='center' valign='top' style='padding-left:5px'><img src='"+host_thumb+"' border='0' class='photoborder'><br><span style='font-size:9px; color:#747474'>"+host_name+"</span></td><td width='250px' valign='top' align='left'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_friends.hangoutinfo[s].HangoutID+"','past','','"+html_friends.hangoutinfo[s].ActionType+"')>"+html_friends.hangoutinfo[s].StartDate+": "+html_friends.hangoutinfo[s].Title.substring(0,25)+"</a><br><span style='padding-left:15px;'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_friends.hangoutinfo[s].HangoutID+"','past','','"+html_friends.hangoutinfo[s].ActionType+"') style='font-size:11px;color:#747474'>"+displayMsg('add / view photo video urls')+"</a></span></td><td width='175px' align='center' valign='top'><span id=rsvploading"+html_friends.hangoutinfo[s].HangoutID+" style='display:none'><img src='"+appPageURL+"/images/rsvp.gif'  border='0'/></span></td><td width='220px' align='left' valign='top'  >"+displayMsg('Invitees')+": "+invited+"<br>"+displayMsg('Accepted')+": "+accepted+"<br></td></tr>";	
						}
						else
						{
							friends_html+="<tr><td width='50px' align='center' valign='top' style='padding-left:5px'><a href='"+host_url+"' target='_blank'><img src='"+host_thumb+"' border='0' class='photoborder'><br><span style='font-size:9px; color:#747474'>"+host_name+"</span></a></td><td width='250px' valign='top' align='left'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_friends.hangoutinfo[s].HangoutID+"','past','','"+html_friends.hangoutinfo[s].ActionType+"')>"+html_friends.hangoutinfo[s].StartDate+": "+html_friends.hangoutinfo[s].Title.substring(0,25)+"</a><br><span style='padding-left:15px;'><a href='javascript:void(0);' onclick=getHtmlPage('view','"+html_friends.hangoutinfo[s].HangoutID+"','past','','"+html_friends.hangoutinfo[s].ActionType+"') style='font-size:11px;color:#747474'>"+displayMsg('add / view photo video urls')+"</a></span></td><td width='175px' align='center' valign='top'><span id=rsvploading"+html_friends.hangoutinfo[s].HangoutID+" style='display:none'><img src='"+appPageURL+"/images/rsvp.gif'  border='0'/></span></td><td width='220px' align='left' valign='top'  >"+displayMsg('Invitees')+": "+invited+"<br>"+displayMsg('Accepted')+": "+accepted+"<br></td></tr>";	
						};	
					}
					friends_html+="<tr><td colspan='4' align='right'>"+paging+"</td></tr></table></td></tr><tr><td class='schedulebottom' height='11px' valign='top' align='center'></td></tr></table></td></tr></table></td></tr>";
					if(document.getElementById('friendshangouts'))
					{
						document.getElementById('friendshangouts').innerHTML = friends_html;
						document.getElementById('pg_loader_'+context).style.display='none';
						if(pageno>1)
						{
							document.getElementById(context+'first').style.display='block';
							document.getElementById(context+'prev').style.display='block';
						}
						document.getElementById(context+pageno).style.fontSize="11px";						
						document.getElementById(context+pageno).style.fontWeight="bold";
						document.getElementById(context+pageno).style.Color="#016497";
						document.getElementById(context+pageno).disabled=true;
					}
					adjustPageHeight();
					
				}
				else
				{
					if(document.getElementById('friendshangouts'))
					{
						document.getElementById('friendshangouts').innerHTML='<tr ><td><table cellspacing="0" cellpadding="0" border="0" width="795px"><tr ><td class="scheduletop"><table border="0" width="100%" cellspacing="0" cellpadding="0" align="center" valign="middle" ><tr><td style="padding-left:10px; font-size:11px" class="pageheading">'+displayMsg("Friends Hangouts")+'</td><td align="right"><span id="image_past" style="display:none"><img src="'+appPageURL+'/images/aj_loader.gif" border="0"/></span></td><td width="25px" align="right" style="padding-right:5px; font-size:10px; font-family: Verdana; font-weight:400; "></td></tr></table></td></tr><tr class="noschedulemiddle"><td width="795px"><table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" valign="top" ><tr><td height="8px"></td></tr><tr><td>&nbsp;<br /><br /></td></tr><tr><td align="center" valing="middle" ><img src="'+appPageURL+'/images/nofriendspasthangouts.gif" border="0" /></td></tr><tr><td>&nbsp;</td></tr><tr><td align="center" valing="middle"><input type="button" id="btn_create" class="button" value="Create Hangout" name="B1" onclick=getHtmlPage("create","","") /><br /><br /><br /></td></tr></table></td></tr><tr><td class="noschedulebottom" height="11px" valign="top" align="center"></td></tr></table></td></tr></table></td></tr>';
										
					}
				}
			}
		}
	}
}
function show_responses(id)
{
	debug("show_responses");
	if(document.getElementById('responses_list_'+rsvp_hid) && rsvp_hid!='')
	{
		document.getElementById('responses_list_'+rsvp_hid).style.display='none';
		rsvp_hid = '';
	}
	rsvp_hid=id;
	var responses="<table style='border:1px #486CAE solid; background-color:#EFF7FF' class='cssdropdown'><tr><td><a href='javascript:void(0);' onclick=rsvp_response(\"Yes\",\""+id+"\")>"+displayMsg('Yes')+"</a><td></tr><tr><td><a href='javascript:void(0);' onclick=rsvp_response(\"No\",\""+id+"\")>"+displayMsg('No')+"</a></td></tr><tr><td><a href='javascript:void(0);' onclick=rsvp_response(\""+escape('May be')+"\",\""+id+"\")>"+displayMsg('May be')+"</a></td></tr></table>";
	if(param!='view')
	{
		document.getElementById('responses_list_'+id).innerHTML=responses;
		document.getElementById('responses_list_'+id).style.display='block';	
	}
	else
	{
		document.getElementById('htmlsel').innerHTML = responses;
		document.getElementById('ddl_span').style.display='block';
	}
}

function rsvp_response(val,id)
{
	debug("rsvp_response");
	if(param!='view')
	{
		document.getElementById('rsvploading'+id).style.display='block';
		document.getElementById('responses_list_'+id).innerHTML='';
		document.getElementById('responses_list_'+id).style.display='none';
		document.getElementById(id).style.display='none';	
		document.getElementById('img_'+id).style.display='none';
	}	
	else
	{
		//document.getElementById('htmlsel').innerHTML = responses;
		document.getElementById('ddl_span').style.display='none';
		if(document.getElementById('aa'))
		{
			var y=unescape(val);
			document.getElementById('aa').innerHTML=displayMsg(y);
		}
	}
	store_response(id,val);
}
function store_response(hid,val)
{
	debug("store_response");
	/*u=0;
	var y;
	var x=val;//document.getElementById('ddl').selectedIndex;*/
	var params = {};
    params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
    params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON; 
	/*if(param != 'view')
	{
		document.getElementById('rsvploading'+hid).style.display='block';
		document.getElementById('rsvp'+hid).style.display='none';
	}
	if(x==0)
	{
		y=displayMsg('Yes'); //document.getElementById('ddl').options[x].text;
	}
	else if(x==1)
	{
		y=displayMsg('No');
	}
	else if(x==2)
	{
		y=displayMsg('May be');
	}
	
	else
	{
		if(document.getElementById('aa'))
		{
			document.getElementById('aa'+hid).innerHTML=y;
			document.getElementById('ddl_span'+hid).style.display='none';	
		}
	}*/
	if(param == 'view')
	{
		var resp_arr=new Array();
		resp_arr=GetFriendDataById(hostid);
		var json_obj="";
		if(resp_arr!=0)
		{
			json_obj={"osid":hostid,"name":resp_arr[0],"imageURL":resp_arr[1],"profileURL":resp_arr[2]};
		}
		
	}
	if(val=="Yes")
	{
		var url= appServletURL+"/UpdateHangoutAction?"+ urlParams.join('');
		postdata = { hid : hid, uids : hostid, action : 2, hostid: hostid , appid:appId , token:token};
		params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
		function RSVPyes_callback(response) 
		{   
			if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null || response.errors[0]=="Error 400")
			{
				err_conunt++;
				if(err_conunt>4)
				{
					var message = Customized_ErrorMessages('servlet');
					 alert(message);
					 err_conunt=0;
					if(param!='view')
					{
						document.getElementById('rsvploading'+hid).style.display='block';
					}
					 return;
				}
				else
				{
					store_response(hid,val);
				}
			}
			else
			{
				var html = eval('('+response.text+')');  
				var c=0;
				if(html.status==1)
				{
					if(param == 'view')
					{
						for(var i=0;await_arr.length > i;i++)
						{
							if(await_arr[i].osid == hostid)	
							{
								await_arr.splice(i,1);        /////////////  pop
								c=1;
							}
						}
						for(var i=0;jsonvar.MayBePersons.length > i;i++)
						{
							if(jsonvar.MayBePersons[i].osid == hostid)
							{
								jsonvar.MayBePersons.splice(i,1);        /////////////  pop
								c=1;
							}
						}
						for(var i=0;jsonvar.RejectedPersons.length > i;i++)
						{
							if(jsonvar.RejectedPersons[i].osid == hostid)
							{
								jsonvar.RejectedPersons.splice(i,1);         //////////// pop
								c=1;
							}
						}
						if(c==1)
						{
							jsonvar.acceptedPersons.push(json_obj); //////////// push
						}
						document.getElementById('hangout_media').style.display='block';
						responses_list(displayMsg('Awaiting response'),await_arr,'await_list','await_content','seeless');
						responses_list(displayMsg('Accepted'),jsonvar.acceptedPersons,'acc_list','acc_content','seeless');
						responses_list(displayMsg('May be'),jsonvar.MayBePersons,'maybe_list','maybe_content','seeless');
						responses_list(displayMsg('Rejected'),jsonvar.RejectedPersons,'reject_list','reject_content','seeless');
						media_links();
					}
					else
					{
						getHangouts('scheduled',1,1);
						getHangouts('new',1,1);
					}
				}
				else
				{
					alert(displayMsg("rsvpnotup"));
				}
			}
		};
		gadgets.io.makeRequest(url,RSVPyes_callback,params);
	}
	else if(val=="No")
	{
		url = appServletURL+"/UpdateHangoutAction?"+ urlParams.join('');
		postdata = { hid : hid, uids : hostid, action : 4, hostid: hostid , appid:appId , token:token};
		params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
		function RSVPno_callback(response) 
		{        
			if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null || response.errors[0]=="Error 400")
			{
				err_conunt++;
				if(err_conunt>4)
				{
					var message = Customized_ErrorMessages('servlet');
					 alert(message);
					 err_conunt=0;
					 if(param!='view')
					{
						document.getElementById('rsvploading'+id).style.display='block';
					}
					 return;
				}
				else
				{
					store_response(hid,val);
				}
			}
			else
			{
				var html = eval('('+response.text+')');  
				var c=0;
				if(html.status==1)
				{
					if(param == 'view')
					{
						for(var i=0;await_arr.length > i;i++)
						{
							if(await_arr[i].osid == hostid)	
							{
								await_arr.splice(i,1);        /////////////  pop
								c=1;
							}
						}
						for(var i=0;jsonvar.acceptedPersons.length > i;i++)
						{
							if(jsonvar.acceptedPersons[i].osid == hostid)
							{
								jsonvar.acceptedPersons.splice(i,1);    //////// pop
								c=1;
							}
						}
						for(var i=0;jsonvar.MayBePersons.length > i;i++)
						{
							if(jsonvar.MayBePersons[i].osid == hostid)
							{
								jsonvar.MayBePersons.splice(i,1);        /////////////  pop
								c=1;
							}
						}
						if(c==1)
						{
							jsonvar.RejectedPersons.push(json_obj); //////////// push	
						}
						document.getElementById('hangout_media').style.display='none';
						responses_list(displayMsg('Awaiting response'),await_arr,'await_list','await_content','seeless');
						responses_list(displayMsg('Accepted'),jsonvar.acceptedPersons,'acc_list','acc_content','seeless');
						responses_list(displayMsg('May be'),jsonvar.MayBePersons,'maybe_list','maybe_content','seeless');
						responses_list(displayMsg('Rejected'),jsonvar.RejectedPersons,'reject_list','reject_content','seeless');
					}
					else
					{
						getHangouts('scheduled',1,1);
						getHangouts('new',1,1);
					}
				}
				else
				{
					alert(displayMsg("rsvpnotup"));
				}
			}
		};
		gadgets.io.makeRequest(url,RSVPno_callback,params);
	}
	else if(unescape(val)=="May be")
	{
		url = appServletURL+"/UpdateHangoutAction?"+ urlParams.join('');
		postdata = { hid : hid, uids : hostid, action : 3, hostid: hostid , appid:appId , token:token};
		params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
		function RSVPmaybe_callback(response) 
		{        
			if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null || response.errors[0]=="Error 400")
			{
				err_conunt++;
				if(err_conunt>4)
				{
					var message = Customized_ErrorMessages('servlet');
					 alert(message);
					 err_conunt=0;
					 if(param!='view')
					{
						document.getElementById('rsvploading'+id).style.display='block';
					}
					 return;
				}
				else
				{
					store_response(hid,val);
				}
			}
			else
			{
				var html = eval('('+response.text+')');  
				var c=0;
				if(html.status==1)
				{
					if(param == 'view')
					{
						for(var i=0;await_arr.length > i;i++)
						{
							if(await_arr[i].osid == hostid)	
							{
								await_arr.splice(i,1);        /////////////  pop
								c=1;
							}
						}
						for(var i=0;jsonvar.RejectedPersons.length > i;i++)
						{
							if(jsonvar.RejectedPersons[i].osid == hostid)
							{
	
								jsonvar.RejectedPersons.splice(i,1);         //////////// pop
								c=1;
							}
						}
						for(var i=0;jsonvar.acceptedPersons.length > i;i++)
						{
							if(jsonvar.acceptedPersons[i].osid == hostid)
							{
								jsonvar.acceptedPersons.splice(i,1);    //////// pop
								c=1;
							}
						}
						if(c==1)
						{
							jsonvar.MayBePersons.push(json_obj); //////////// push	
						}
						document.getElementById('hangout_media').style.display='none';
						responses_list(displayMsg('Awaiting response'),await_arr,'await_list','await_content','seeless');
						responses_list(displayMsg('Accepted'),jsonvar.acceptedPersons,'acc_list','acc_content','seeless');
						responses_list(displayMsg('May be'),jsonvar.MayBePersons,'maybe_list','maybe_content','seeless');
						responses_list(displayMsg('Rejected'),jsonvar.RejectedPersons,'reject_list','reject_content','seeless');
					}
					else
					{
						getHangouts('scheduled',1,1);
						getHangouts('new',1,1);
					}
				}
				else
				{
					alert(displayMsg("rsvpnotup"));
				}
			}
		};
		gadgets.io.makeRequest(url,RSVPmaybe_callback,params);
	}
}
function Pagination(pg_no,id,context,pages)
{
	debug("Pagination");
	var a=0;from=0;to=0;
	paging='<table><tr><td><img id="pg_loader_'+context+'" src="'+appPageURL+'/images/rsvp.gif" border="0" style="display:none"/></td>';
	var c='';
	if(context=='showpast')
	{
		c='showpastdata';
	}
	else
	{
		c='no';	
	}
	if(pg_no<=5)
	{
		if(pages>5)
		{
			paging+='<td><img id="'+context+'first" src="'+appPageURL+'/images/double_arrow.gif" onclick=getHangouts("'+context+'",1,this.id,"'+c+'") style="display:none" class="btn" /></td>';
			paging+='<td><img id="'+context+'prev" src="'+appPageURL+'/images/single_arrow.gif" onclick=showPrev('+pg_no+',"'+context+'","'+pages+'","'+c+'") style="display:none" class="btn" /></td>';
				
			for(var i=1;i<=5;i++)
			{
				if(i==pg_no)
				{
					paging+='<td><input id="'+context+i+'" value="'+i+'" class="btn" onclick=getHangouts("'+context+'","'+i+'",this.id,"'+c+'") type="button" style="font-size:11px; cursor:default; font-weight:bold" disabled="true"/></td>';	
				}
				else
				{
					paging+='<td><input id="'+context+i+'" value="'+i+'" class="btn" onclick=getHangouts("'+context+'","'+i+'",this.id,"'+c+'") type="button"/></td>';	
				}
				pos[a]=i;
				a++;
			}
			paging+='<td><img id="'+context+'next" src="'+appPageURL+'/images/single_arrow01.gif" onclick=showNext('+pg_no+',"'+context+'","'+pages+'","'+c+'") class="btn"  /></td>';
			paging+='<td><img id="'+context+'last" src="'+appPageURL+'/images/double_arrow01.gif" onclick=getHangouts("'+context+'","'+pages+'",this.id,"'+c+'") class="btn"  /></td>';
		}
		else if(pages>0)
		{	
			paging+='<td><img id="'+context+'first" src="'+appPageURL+'/images/double_arrow.gif" onclick=getHangouts("'+context+'",1,this.id,"'+c+'") style="display:none" class="btn" /></td>';
			paging+='<td><img id="'+context+'prev" src="'+appPageURL+'/images/single_arrow.gif" onclick=showPrev('+pg_no+',"'+context+'","'+pages+'","'+c+'") style="display:none" class="btn" /></td>';
			for(var i=1;i<=pages;i++)
			{
				if(i==pg_no)
				{
					paging+='<td><input id="'+context+i+'" value="'+i+'" class="btn" onclick=getHangouts("'+context+'","'+i+'",this.id,"'+c+'") type="button" style="font-size:11px; cursor:default; font-weight:bold" disabled="true"/></td>';	
				}
				else
				{
					paging+='<td><input id="'+context+i+'" value="'+i+'" class="btn" onclick=getHangouts("'+context+'","'+i+'",this.id,"'+c+'") type="button"/></td>';	
				}
			}
			if(pages>1 && pg_no!=pages)
			{
				paging+='<td><img id="'+context+'next"src="'+appPageURL+'/images/single_arrow01.gif" onclick=showNext('+pg_no+',"'+context+'","'+pages+'","'+c+'") class="btn" /></td>';
				paging+='<td><img id="'+context+'last"src="'+appPageURL+'/images/double_arrow01.gif" onclick=getHangouts("'+context+'","'+pages+'",this.id,"'+c+'") class="btn" /></td>';
			}
		}
	}
	else if(pg_no>5 && pg_no<=pages)
	{
		
		var st=0;
		var end=0;
		if(id==(context+'prev'))
		{
			/*if((pg_no+4)==pages)
			{
				st=pg_no;
				end=pg_no+4;	
			}
			else
			{*/
				st=pg_no-4;
				end=pg_no;	
			//}
			paging+='<td><img id="'+context+'first" src="'+appPageURL+'/images/double_arrow.gif" onclick=getHangouts("'+context+'",1,this.id,"'+c+'") class="btn" /></td>';
			paging+='<td><img id="'+context+'prev" src="'+appPageURL+'/images/single_arrow.gif" onclick=showPrev('+pg_no+',"'+context+'","'+pages+'","'+c+'") class="btn" /></td>';
			for(var i=st;i<=end;i++)
			{
				if(i==pg_no)
				{
					paging+='<td><input id="'+context+i+'" value="'+i+'" class="btn" onclick=getHangouts("'+context+'","'+i+'",this.id,"'+c+'") type="button" style="font-size:11px; cursor:default; font-weight:bold" disabled="true"/></td>';	
				}
				else
				{
					paging+='<td><input id="'+context+i+'" value="'+i+'" class="btn" onclick=getHangouts("'+context+'","'+i+'",this.id,"'+c+'") type="button"/></td>';	
				}	
				pos[a]=i;
				a++;
			}
			if( pg_no!=pages)
			{
				paging+='<td><img id="'+context+'next" src="'+appPageURL+'/images/single_arrow01.gif" onclick=showNext('+pg_no+',"'+context+'","'+pages+'","'+c+'") class="btn" /></td>';
				paging+='<td><img id="'+context+'last" src="'+appPageURL+'/images/double_arrow01.gif" onclick=getHangouts("'+context+'","'+pages+'",this.id,"'+c+'") class="btn" /></td>';
			}
		}
		else if(id==(context+'next') || id==(context+'last'))
		{
			st=pg_no-4;
			end=pg_no;
			paging+='<td><img id="'+context+'first" src="'+appPageURL+'/images/double_arrow.gif"onclick=getHangouts("'+context+'",1,this.id,"'+c+'") class="btn" /></td>';
			paging+='<td><img id="'+context+'prev" src="'+appPageURL+'/images/single_arrow.gif"onclick=showPrev('+pg_no+',"'+context+'","'+pages+'","'+c+'") class="btn" /></td>';
			for(var i=st;i<=end;i++)
			{
				if(i==pg_no)
				{
					paging+='<td><input id="'+context+i+'" value="'+i+'" class="btn" onclick=getHangouts("'+context+'","'+i+'",this.id,"'+c+'") type="button" style="font-size:11px; cursor:default; font-weight:bold" disabled="true"/></td>';	
				}
				else
				{
					paging+='<td><input id="'+context+i+'" value="'+i+'" class="btn" onclick=getHangouts("'+context+'","'+i+'",this.id,"'+c+'") type="button"/></td>';	
				}	
				pos[a]=i;
				a++;
			}
			if( pg_no!=pages)
			{
				paging+='<td><img id="'+context+'next" src="'+appPageURL+'/images/single_arrow01.gif" onclick=showNext('+pg_no+',"'+context+'","'+pages+'","'+c+'") class="btn" /></td>';
				paging+='<td><img id="'+context+'last" src="'+appPageURL+'/images/double_arrow01.gif" onclick=getHangouts("'+context+'","'+pages+'",this.id,"'+c+'") class="btn" /></td>';
			}
		}
		else 
		{
			for(var i=0;i<pos.length;i++)
			{
				if(pos[i]==pg_no)
				{
					paging+='<td><img id="'+context+'first" src="'+appPageURL+'/images/double_arrow.gif" onclick=getHangouts("'+context+'",1,this.id,"'+c+'") class="btn" /></td>';
					paging+='<td><img id="'+context+'prev" src="'+appPageURL+'/images/single_arrow.gif" onclick=showPrev('+pg_no+',"'+context+'","'+pages+'","'+c+'") class="btn" /></td>';
					
					for(var b=0;b<=4;b++)
					{
						if(i==pg_no)
						{
							paging+='<td><input id="'+context+(pg_no-(i-b))+'" value="'+(pg_no-(i-b))+'" class="btn" onclick=getHangouts("'+context+'","'+(pg_no-(i-b))+'",this.id,"'+c+'") type="button" style="font-size:11px; cursor:default; font-weight:bold" disabled="true"/></td>';	
						}
						else
						{
							paging+='<td><input id="'+context+(pg_no-(i-b))+'" value="'+(pg_no-(i-b))+'" class="btn" onclick=getHangouts("'+context+'","'+(pg_no-(i-b))+'",this.id,"'+c+'") type="button"/></td>';		
						}
					}
					if( pg_no!=pages)
					{
						paging+='<td><img id="'+context+'next" src="'+appPageURL+'/images/single_arrow01.gif" onclick=showNext('+pg_no+',"'+context+'","'+pages+'","'+c+'") class="btn" /></td>';
						paging+='<td><img id="'+context+'last" src="'+appPageURL+'/images/double_arrow01.gif" onclick=getHangouts("'+context+'","'+pages+'",this.id,"'+c+'") class="btn" /></td>';
					}
				}
			}
		}
		
		
	}
	paging+='</tr></table>';
	if(paging=="<table><tr></tr></table>")
	{
		paging="";	
	}
}
function showNext(pg,context,pages,c)
{
	debug("showNext");
	if((pg+1)<=pages)
	{
		Pagination(pg+1,context+"next",context,c);
		getHangouts(context,pg+1,context+"next",c);
	}
	
}
function showPrev(pg,context,pages,c)
{
	debug("showPrev");
	if((pg-1)!=0)
	{
		Pagination(pg-1,"prev",context,c);
		getHangouts(context,pg-1,context+"prev",c);
	}
}

function getInvitedDetails(hid,id_array,host_name,checkPast)
{
	debug("getInvitedDetails");
	var iID="";
	var counter=0;
	if(id_array.length!=0)
	{
		 if(counter<1)
		 {				
			var data=GetFriendDataById(id_array[0].osid);				
			if(data!=0)
			{		
				if(id_array.length >1)
				{
					if(data[0]==displayMsg("You"))
					{
						iID+=data[0] + "...<a href='javascript:void(0);' onclick=getHtmlPage('view','"+hid+"','"+checkPast+"')><img src='"+appPageURL+"/images/rt_arrows.gif' border='0'></a>";
					}
					else
					{
						iID+="<a target='_blank' href='"+unescape(data[2])+"'>"+unescape(data[0]) + "</a>...<a href='javascript:void(0);' onclick=getHtmlPage('view','"+hid+"','"+checkPast+"')><img src='"+appPageURL+"/images/rt_arrows.gif' border='0'></a>";
					}
				}
				else if(id_array.length =1)
				{
					if(data[0]==displayMsg("You"))
					{
						iID+=data[0];
					}
					else
					{
						iID+="<a target='_blank' href='"+unescape(data[2])+"'>"+unescape(data[0]) + "</a>";
					}
				}
			}
			else 
			{
				if(id_array[0].name!='' && typeof(id_array[0].name)!='undefined')
				{
					if(id_array.length >1)
					{
						iID+="<a target='_blank' href='"+unescape(id_array[0].profileURL)+"'>"+unescape(id_array[0].name)+ "</a>...<a href='javascript:void(0);' onclick=getHtmlPage('view','"+hid+"','"+checkPast+"')><img src='"+appPageURL+"/images/rt_arrows.gif' border='0'></a>";
					}
					else if(id_array.length =1)
					{
						iID+="<a target='_blank' href='"+unescape(id_array[0].profileURL)+"'>"+unescape(id_array[0].name)+ "</a>";
					}
				}
				else
				{
					if(id_array.length >1)
					{
						iID+=displayMsg("hostFriend")+"...<a href='javascript:void(0);' onclick=getHtmlPage('view','"+hid+"','"+checkPast+"')><img src='"+appPageURL+"/images/rt_arrows.gif' border='0'></a>";
					}
					else if(id_array.length =1)
					{
						iID+=displayMsg("hostFriend");
					}
				}
			}	
			counter++;
		 }			
	}
	else
	{
		iID=displayMsg("None");
	}	
	return iID;
}
//getting accepted details
function getAcceptedDetails(hid,id_array,host_name,checkPast)
{
	debug("getAcceptedDetails");
	var iID="";
	var counter=0;
	if(id_array.length!=0)
	{
		for(var arr_index=0;arr_index < id_array.length;arr_index++)
		{					
			 if(counter<1)
			 {
				var data=GetFriendDataById(id_array[arr_index].osid);
				if(data!=0)
				{				
					if(id_array.length >1)
					{
						if(data[0]==displayMsg("You"))
						{
							iID+=data[0] + "...<a href='javascript:void(0);' onclick=getHtmlPage('view','"+hid+"','"+checkPast+"')><img src='"+appPageURL+"/images/rt_arrows.gif' border='0'></a>";
						}
						else
						{
							iID+="<a target='_blank' href='"+unescape(data[2])+"'>"+unescape(data[0]) + "</a>...<a href='javascript:void(0);' onclick=getHtmlPage('view','"+hid+"','"+checkPast+"')><img src='"+appPageURL+"/images/rt_arrows.gif' border='0'></a>";
						}
					}
					else if(id_array.length=1)
					{
						if(data[0]==displayMsg("You"))
						{
							iID+=data[0];
						}
						else
						{
							iID+="<a target='_blank' href='"+unescape(data[2])+"'>"+unescape(data[0]) + "</a>";
						}
					}
				}
				else
				{
					if(id_array[0].name!='' && typeof(id_array[0].name)!='undefined')
					{
						if(id_array.length >1)
						{
							iID+="<a target='_blank' href='"+unescape(id_array[0].profileURL)+"'>"+unescape(id_array[0].name)+ "</a>...<a href='javascript:void(0);' onclick=getHtmlPage('view','"+hid+"','"+checkPast+"')><img src='"+appPageURL+"/images/rt_arrows.gif' border='0'></a>";
						}
						else if(id_array.length =1)
						{
							iID+="<a target='_blank' href='"+unescape(id_array[0].profileURL)+"'>"+unescape(id_array[0].name)+ "</a>";
						}
					}
					else
					{
						if(id_array.length >1)
						{
							iID+=displayMsg("hostFriend")+"...<a href='javascript:void(0);' onclick=getHtmlPage('view','"+hid+"','"+checkPast+"')><img src='"+appPageURL+"/images/rt_arrows.gif' border='0'></a>";
						}
						else if(id_array.length =1)
						{
							iID+=displayMsg("hostFriend");
						}
					}
				}	
				counter++;
			 }			
		}
	}
	else
	{
		iID=displayMsg("None");
	}	
	return iID;
}
/////////////////////////  rsvp dropdown   ////////////////

function selectme(hid,val)
{
	debug("selectme");
	u=0;
	var y;
	var x=val;//document.getElementById('ddl').selectedIndex;
	var params = {};
    params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
    params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON; 
	if(param != 'view')
	{
		document.getElementById('rsvploading'+hid).style.display='block';
		document.getElementById('rsvp'+hid).style.display='none';
	}
	if(x==0)
	{
		y=displayMsg('Yes'); //document.getElementById('ddl').options[x].text;
	}
	else if(x==1)
	{
		y=displayMsg('No');
	}
	else if(x==2)
	{
		y=displayMsg('May be');
	}
	if(param == 'view')
	{
		var resp_arr=new Array();
		resp_arr=GetFriendDataById(hostid);
		var json_obj="";
		if(resp_arr!=0)
		{
			json_obj={"osid":hostid,"name":resp_arr[0],"imageURL":resp_arr[1],"profileURL":resp_arr[2]};
		}
		document.getElementById('aa').innerHTML=y;
		document.getElementById('ddl_span').style.display='none';
	}
	else
	{
		document.getElementById('aa'+hid).innerHTML=y;
		document.getElementById('ddl_span'+hid).style.display='none';	
	}
	if(x==0)
	{
		var url= appServletURL+"/UpdateHangoutAction?"+ urlParams.join('');
		postdata = { hid : hid, uids : hostid, action : 2, hostid: hostid ,appid:appId,token:token};
		params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
		function RSVPyes_callback(response) 
		{   
			if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
			{
				err_conunt++;
				if(err_conunt>4)
				{
					var message = Customized_ErrorMessages('servlet');
					 alert(message);
					 err_conunt=0;
					 document.getElementById("rsvploading"+hid).style.display='none';
					document.getElementById('rsvp'+hid).style.display='block';
					 return;
				}

				else
				{
					selectme(hid,x);
				}
			}
			else
			{
				var html = eval('('+response.text+')');  
				var c=0;
				if(html.status==1)
				{
					if(param == 'view')
					{
						for(var i=0;await_arr.length > i;i++)
						{
							if(await_arr[i].osid == hostid)	
							{
								await_arr.splice(i,1);        /////////////  pop
								c=1;
							}
						}
						for(var i=0;jsonvar.MayBePersons.length > i;i++)
						{
							if(jsonvar.MayBePersons[i].osid == hostid)
							{
								jsonvar.MayBePersons.splice(i,1);        /////////////  pop
								c=1;
							}
						}
						for(var i=0;jsonvar.RejectedPersons.length > i;i++)
						{
							if(jsonvar.RejectedPersons[i].osid == hostid)
							{
								jsonvar.RejectedPersons.splice(i,1);         //////////// pop
								c=1;
							}
						}
						if(c==1)
						{
							jsonvar.acceptedPersons.push(json_obj); //////////// push
						}
							
						
						responses_list(displayMsg('Awaiting response'),await_arr,'await_list','await_content','seeless');
						responses_list(displayMsg('Accepted'),jsonvar.acceptedPersons,'acc_list','acc_content','seeless');
						responses_list(displayMsg('May be'),jsonvar.MayBePersons,'maybe_list','maybe_content','seeless');
						responses_list(displayMsg('Rejected'),jsonvar.RejectedPersons,'reject_list','reject_content','seeless');
					}
					else
					{
							getHangouts('scheduled',1,1);
						getHangouts('new',1,1);
					}
				}
				else
				{
					alert(displayMsg("rsvpnotup"));
				}
			}
		};
		gadgets.io.makeRequest(url,RSVPyes_callback,params);
	}
	else if(x==1)
	{
		url = appServletURL+"/UpdateHangoutAction?"+ urlParams.join('');
		postdata = { hid : hid, uids : hostid, action : 4, hostid: hostid , appid:appId ,token:token};
		params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
		function RSVPno_callback(response) 
		{        
			if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
			{
				err_conunt++;
				if(err_conunt>4)
				{
					var message = Customized_ErrorMessages('servlet');
					 alert(message);
					 err_conunt=0;

					 document.getElementById("rsvploading"+hid).style.display='none';
					document.getElementById('rsvp'+hid).style.display='block';
					 return;
				}
				else
				{
					selectme(hid,x);
				}
			}
			else
			{
				var html = eval('('+response.text+')');  
				var c=0;
				if(html.status==1)
				{
					if(param == 'view')
					{
						for(var i=0;await_arr.length > i;i++)
						{
							if(await_arr[i].osid == hostid)	
							{
								await_arr.splice(i,1);        /////////////  pop
								c=1;
							}
						}
						for(var i=0;jsonvar.acceptedPersons.length > i;i++)
						{
							if(jsonvar.acceptedPersons[i].osid == hostid)
							{
								jsonvar.acceptedPersons.splice(i,1);    //////// pop
								c=1;
							}
						}
						for(var i=0;jsonvar.MayBePersons.length > i;i++)
						{
							if(jsonvar.MayBePersons[i].osid == hostid)
							{
								jsonvar.MayBePersons.splice(i,1);        /////////////  pop
								c=1;
							}
						}
						if(c==1)
						{
							jsonvar.RejectedPersons.push(json_obj); //////////// push	
						}
	
						responses_list(displayMsg('Awaiting response'),await_arr,'await_list','await_content','seeless');
						responses_list(displayMsg('Accepted'),jsonvar.acceptedPersons,'acc_list','acc_content','seeless');
						responses_list(displayMsg('May be'),jsonvar.MayBePersons,'maybe_list','maybe_content','seeless');
						responses_list(displayMsg('Rejected'),jsonvar.RejectedPersons,'reject_list','reject_content','seeless');
					}
					else
					{
						getHangouts('scheduled',1,1);
						getHangouts('new',1,1);
					}
				}
				else
				{
					alert(displayMsg("rsvpnotup"));
				}
			}
		};
		gadgets.io.makeRequest(url,RSVPno_callback,params);
	}
	else if(x==2)
	{
		url = appServletURL+"/UpdateHangoutAction?"+ urlParams.join('');
		postdata = { hid : hid, uids : hostid, action : 3, hostid: hostid , appid:appId ,token:token};
		params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
		function RSVPmaybe_callback(response) 
		{        
			if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
			{
				err_conunt++;
				if(err_conunt>4)
				{
					var message = Customized_ErrorMessages('servlet');
					 alert(message);
					 err_conunt=0;
					 document.getElementById("rsvploading"+hid).style.display='none';
					document.getElementById('rsvp'+hid).style.display='block';
					 return;
				}
				else
				{
					selectme(hid,x);
				}
			}
			else
			{
				var html = eval('('+response.text+')');  
				var c=0;
				if(html.status==1)
				{
					if(param == 'view')
					{
						for(var i=0;await_arr.length > i;i++)
						{
							if(await_arr[i].osid == hostid)	
							{
								await_arr.splice(i,1);        /////////////  pop
								c=1;
							}
						}
						for(var i=0;jsonvar.RejectedPersons.length > i;i++)
						{
							if(jsonvar.RejectedPersons[i].osid == hostid)
							{
	
								jsonvar.RejectedPersons.splice(i,1);         //////////// pop
								c=1;
							}
						}
						for(var i=0;jsonvar.acceptedPersons.length > i;i++)
						{
							if(jsonvar.acceptedPersons[i].osid == hostid)
							{
								jsonvar.acceptedPersons.splice(i,1);    //////// pop
								c=1;
							}
						}
						if(c==1)
						{
							jsonvar.MayBePersons.push(json_obj); //////////// push	
						}
	
						responses_list(displayMsg('Awaiting response'),await_arr,'await_list','await_content','seeless');
						responses_list(displayMsg('Accepted'),jsonvar.acceptedPersons,'acc_list','acc_content','seeless');
						responses_list(displayMsg('May be'),jsonvar.MayBePersons,'maybe_list','maybe_content','seeless');
						responses_list(displayMsg('Rejected'),jsonvar.RejectedPersons,'reject_list','reject_content','seeless');
					}
					else
					{
						getHangouts('scheduled',1,1);
						getHangouts('new',1,1);
					}
				}
				else
				{
					alert(displayMsg("rsvpnotup"));
				}
			}
		};
		gadgets.io.makeRequest(url,RSVPmaybe_callback,params);
	}
}

function whichElement(ex)
{
	debug("whichElement");
	var targ;
	
	if (!ex)
	{
	  var ex=window.event;
	}
	if (ex.target)
	{
	  targ=ex.target;
	}
	else if (ex.srcElement)
	{
	  targ=ex.srcElement;
	}
	if (targ.nodeType==3) // defeat Safari bug
	{
	  targ = targ.parentNode;
	}
	var tname;
	tname=targ.tagName;
	if(tname == 'BODY' || tname == 'A' || tname == 'DIV' || tname == 'TABLE' || tname == 'TR' || tname == 'TD')
	{
		if(param == 'view' )
		{
			document.getElementById('ddl_span').style.display='none';
		}
		else if(param == 'schedule' || param == 'new')
		{
			if(document.getElementById('responses_list_'+rsvp_hid) && rsvp_hid!='')
			{
				document.getElementById('responses_list_'+rsvp_hid).style.display='none';
				rsvp_hid = '';
			}
		}
		else if(param=='create' || param=='edit')
		{
			document.getElementById('search').value=displayMsg('search');
			document.getElementById('sample').style.display='none';
			document.getElementById('getHangouts').style.display='none';
			document.getElementById('getPastLocations').style.display='none';	

		}
		else if(param=='view')
		{
			document.getElementById('sample').style.display='none';
			document.getElementById('showMedia_div').style.display='none';
		}
	}
}
///////////////////// end rsvp dropdown  ///////////////////////
var IE = document.all?true:false;
function UpdateStatus(e,action,hid,uids,auids,title)
{
	if (!IE) {document.captureEvents(Event.MOUSEMOVE)};
	if(param == 'view')
	{
		document.getElementById('csscancelhangout').style.top = 180;
	}
	else if(param == 'schedule')
	{
		if(IE)
		{ 
			document.getElementById('csscancelhangout').style.top = event.clientY + document.body.scrollTop -150;
		}
		else
		{  
			document.getElementById('csscancelhangout').style.top = e.pageY -150;
		}
	};
	if(action=="cancel")
	{
		
		var htmltbl = "<table cellpadding='0' cellspacing=0 width='420px' ><tr><td valign='top' colspan='2'  class='canvasviewTitleBar'><span class='pageheading' style='padding:10px; color:#FFFFFF'> "+displayMsg('Cancel Hangout')+"</span><span style='padding-left:236px'><a style='color:#ffffff' href='javascript:void(0);' onclick=closewin('csscancelhangout')><b>"+displayMsg('Close')+" X</b></a></span></td></tr>";
			htmltbl += "<tr><td height='15px' ></td></tr><tr>";
			htmltbl += "<td width='590px' style='padding-left:45px' colspan='2'>"+displayMsg('Do you really want to cancel this hangout?')+"<br><br></td></tr><tr>";
			htmltbl += "<td align='center' colspan='2'><input type='button' id='cancelhangoutbtn' class='butto' value='"+displayMsg('Yes')+"' name='cancelhangoutbtn' onClick=confirmcancelhangout(this.value,'"+hid+"','"+title+"','"+uids+"') />";
			htmltbl += "&nbsp;&nbsp;<input type='button' id='cancelhangoutbtn1' class='butto' value='"+displayMsg('No')+"' name='cancelhangoutbtn1' onClick=confirmcancelhangout(this.value,'"+hid+"','"+title+"','"+uids+"') /><br/><br/>";
			htmltbl += "</td></tr></table>";
			if(document.getElementById('cancelhangout1'))
			{
				document.getElementById('sample').style.display='block';
				document.getElementById('csscancelhangout').style.display='block';
				document.getElementById('cancelhangout1').innerHTML=htmltbl;
			}
	}
	
}
////////////---------Create Hangout---------------//////////////////


function getCreateHangout()
{
	selector();
	u++;
	document.getElementById('ld_create').style.display='none';
	document.getElementById('btn_create').disabled=false;
	document.getElementById('htitle').value = '';
	document.getElementById('sdate').value = '';
	document.getElementById('hothertype').value = '';
	document.getElementById('stime').value = '09:00';
	document.getElementById('edate').value = '';
	document.getElementById('etime').value = '09:00';
	document.getElementById('AllDay').checked= false;
	document.getElementById('etimetd').style.display = 'block';
	document.getElementById('vaddress1').value = '';
	document.getElementById('vstreet').value = '';
	document.getElementById('vcity').value = '';
	document.getElementById('message').value = '';
//	document.getElementById('friends').innerHTML = '';
	document.getElementById('hothertype').style.display = 'none';
	document.getElementById('leftchar').innerHTML=500;
}

function getPastLocations()
{
	
	var refreshInterval=0;
	if(cntr=='eng')
	{
		urlParams=['ctry=', 'US', '&lang=', 'en'];
	}
	else if(cntr=='prt')
	{
		urlParams=['ctry=', 'BR', '&lang=', 'pt'];	
	};
	var url=appServletURL+"/GetHangoutLocation?"+ urlParams.join('');
	var ts = new Date().getTime();
	var sep = "?";
	if (refreshInterval && refreshInterval > 0) 
	{
	   ts = Math.floor(ts / (refreshInterval * 1000));
	}
	if (url.indexOf("?") > -1) 
	{
	   sep = "&";
	}
	url = [ url, sep, "nocache=", ts ].join("");
	post_params();
	postdata = {    hostid : hostid,    hcontext : 'past', flag:'location' };
	params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
	gadgets.io.makeRequest(url,callback,params);
	function callback(response)
	{
		if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null || response.errors[0]=="Error 400")
		{
			err_conunt++;
			if(err_conunt>4)
			{
				var message = Customized_ErrorMessages('servlet');
				 alert(message);
				 err_conunt=0;
				 return;
			}
			else
			{
				getPastLocations();
			}
		}
		else
		{
			var locale=eval('('+response.text+')');
			if(locale.location.length!=0)
			{
				document.getElementById('sample').style.display='block';
				var html_locations="<table>";
				
				for(var l=0;l<locale.location.length;l++)
				{
					var cls="";
						if(l%2==0)
						{
							cls="altrow";
						}
						else
						{
							cls="altrow1";
						}	
					var hangout_location=new Array();
					if(locale.location[l].Address2!='' && typeof(locale.location[l].Address2)!='undefined')
					{
						hangout_location.push(locale.location[l].Address2.substring(0,25));
						if(locale.location[l].Address1!='' && typeof(locale.location[l].Address1)!='undefined')
						{
							hangout_location.push(locale.location[l].Address1.substring(0,25));
							if(locale.location[l].city!='' && typeof(locale.location[l].city)!='undefined')
							{
								hangout_location.push(locale.location[l].city.substring(0,25));
							}
						}
						else if(locale.location[l].city!='' && typeof(locale.location[l].city)!='undefined')
						{
							hangout_location.push(locale.location[l].city.substring(0,25));
						}
					}
					else if(locale.location[l].Address1!='' && typeof(locale.location[l].Address1)!='undefined')
					{
						hangout_location.push(locale.location[l].Address1.substring(0,25));
						if(locale.location[l].city!='' && typeof(locale.location[l].city)!='undefined')
						{
							hangout_location.push(locale.location[l].city.substring(0,25));
						}
					}
					else if(locale.location[l].city!='' && typeof(locale.location[l].city)!='undefined')
					{
						hangout_location.push(locale.location[l].city.substring(0,25));
					}
					html_locations+="<tr class='"+cls+"'><td><a href='javascript:void(0);' onclick=\"populate('','','','','','','','"+escape(hangout_location)+"','locations')\">"+hangout_location+"</td></tr>";
				}
				if(document.getElementById('getPastLocations'))
				{
					document.getElementById('getPastLocations').style.display='block';	
					document.getElementById('location').innerHTML=html_locations;
				}
			}
			else
			{
				html_location='';
				document.getElementById('sample').style.display='none';
				document.getElementById('getPastLocations').style.display='none';	
				alert("No Locations");	
			}
		}
	}
}
function populate(title,typeID,typeName,where,street,city,message,loc,con)
{
	if(con=='locations')
	{
		if(param=='create')
		{
			document.getElementById('vaddress1').value='';
			document.getElementById('vstreet').value='';
			document.getElementById('vcity').value='';	
			document.getElementById('sample').style.display='none';
			document.getElementById('getPastLocations').style.display='none';	

			//loc_count++;
			if((unescape(loc).split(',')).length>=2)
			{
				
				document.getElementById('vaddress1').value=(unescape(loc).split(','))[0];
				if((unescape(loc).split(',')).length>2)
				{
					var i=1;
					while(i<((unescape(loc).split(',')).length-1))
					{
						document.getElementById('vstreet').value+=(unescape(loc).split(','))[i];
						
						if(i!=((unescape(loc).split(',')).length-2))
						{
							document.getElementById('vstreet').value+=',';
						}
						i++;
					}
					
				}
			}
			document.getElementById('vcity').value=(unescape(loc).split(','))[((unescape(loc).split(',')).length-1)];
		}
		else if(param=='edit')
		{
			document.getElementById('editvaddress1').value='';
			document.getElementById('editvstreet').value='';
			document.getElementById('editvcity').value='';	
			document.getElementById('sample').style.display='none';
			document.getElementById('getPastLocations').style.display='none';	

			//loc_count++;
			if((unescape(loc).split(',')).length>=2)
			{
				
				document.getElementById('editvaddress1').value=(unescape(loc).split(','))[0];
				if((unescape(loc).split(',')).length>2)
				{
					var i=1;
					while(i<((unescape(loc).split(',')).length-1))
					{
						document.getElementById('editvstreet').value+=(unescape(loc).split(','))[i];
						
						if(i!=((unescape(loc).split(',')).length-2))
						{
							document.getElementById('editvstreet').value+=',';
						}
						i++;
					}
					
				}
			}
			document.getElementById('editvcity').value=(unescape(loc).split(','))[((unescape(loc).split(',')).length-1)];
		}
	}
	else if(con=='pastdata')
	{
		document.getElementById('sample').style.display='none';
		document.getElementById('getHangouts').style.display='none';
		//spd_count++;
		if(param=='create')
		{
			document.getElementById('htitle').value='';
			document.getElementById('htype').value=0;
			document.getElementById('vaddress1').value='';
			document.getElementById('vstreet').value='';
			document.getElementById('vcity').value='';	
			document.getElementById('message').value='';	
			
			document.getElementById('htitle').value=unescape(title);
			if(typeID>0 && typeID<45)
			{
				document.getElementById('char_other').style.display = 'none';
				document.getElementById('hothertype').style.display = 'none';
				document.getElementById('hothertype').value = '';
				document.getElementById('htype').value=typeID;				
			}
			else
			{
				document.getElementById('htype').value = 45;
				document.getElementById('char_other').style.display = 'block';
				document.getElementById('hothertype').style.display = 'block';
				document.getElementById('hothertype').value = unescape(typeName);
			}
			document.getElementById('vaddress1').value=unescape(where);
			document.getElementById('vstreet').value=unescape(street);
			document.getElementById('vcity').value=unescape(city);	
			document.getElementById('message').value=unescape(message);
		}
		else if(param=='edit')
		{
			document.getElementById('edithtitle').value='';
			document.getElementById('edithtype').value=0;
			document.getElementById('editvaddress1').value='';
			document.getElementById('editvstreet').value='';
			document.getElementById('editvcity').value='';	
			document.getElementById('editmessage').value='';	
			
			document.getElementById('edithtitle').value=unescape(title);
			if(typeID>0 && typeID<45)
			{
				document.getElementById('editchar_other').style.display = 'none';
				document.getElementById('edithothertype').style.display = 'none';
				document.getElementById('edithothertype').value = '';
				document.getElementById('edithtype').value=typeID;		
			}
			else
			{
				document.getElementById('edithtype').value = 45;
				document.getElementById('editchar_other').style.display = 'block';
				document.getElementById('edithothertype').style.display = 'block';
				document.getElementById('edithothertype').value = unescape(typeName);
			}
			document.getElementById('editvaddress1').value=unescape(where);
			document.getElementById('editvstreet').value=unescape(street);
			document.getElementById('editvcity').value=unescape(city);	
			document.getElementById('editmessage').value=unescape(message);
		}
	}
}
function defaultlocation(id)
{
	if(id.checked==true)
	{
		
	}
}
///search control for friends
function selector()
{
	if(id_string.length>0)
	{
		clearArray(id_string);
		clearArray(name_string);
		clearArray(tid_string);
	}
	id_string.length=0;
	name_string.length=0;
	tid_string.length=0;
	for(var z=1;z<pname_arr.length;z++)
	{
		names_arr[z-1]=pname_arr[z];
		ids_arr[z-1]=puid_arr[z];
		tid_arr[z-1]=thumb_arr[z];
	}	
	if(param=='edit')
	{
		for(var x=0;x<canceluids.length;x++)
		{
			for(var y=0;y<ids_arr.length;y++)
			{
				if(ids_arr[y]==canceluids[x])
				{
					id_string.push(ids_arr[y]);
					name_string.push(names_arr[y]);
					tid_string.push(tid_arr[y]);
					/*ids_arr.splice(y,1);
					names_arr.splice(y,1);
					tid_arr.splice(y,1);*/
				}
				//ii++;
			}		
		}
	}
	fsw('widget',5,6,escape('search friends'),'slider');
}
function fsw(div_name,nrows,perrow,msg,c)
{
	/*alert(c);
	alert(div_name+"                 "+c);
	for(var z=0;z<names.length;z++)
	{
		names_arr[z]=names[z];
		ids_arr[z]=ids[z];
		tid_arr[z]=tid[z];
	}	
	*/
	if(typeof(nrows)!='undefined')
	{
		rows=nrows;
	}
	else
	{
		rows=4;
	}
	if(typeof(perrow)!='undefined')
	{
		per_row=perrow;
	}
	else
	{
		per_row=8;
	}
	if(typeof(msg)!='undefined')
	{
		search_msg=unescape(msg);
	}
	else
	{
		search_msg='search friends';
	}
	if(document.getElementById(div_name))
	{
		document.getElementById(div_name).innerHTML='<div id="fsw" align="left" onclick="clear_ddl(event);" ><table border="0px" cellspacing="0" cellpadding="0"><tr><td></td></tr><tr><td align="left" style="width:500px"><input id="search" type="text" value="'+search_msg+'" onmousedown="clear_search()" onkeyup=search_friends("search") style="width:300px;font-size:11px;color:#999999" /></td><td align="right" style="vertical-align:middle;"><a id="show_all" href="javascript:void(0);" style="display:none;font-family: Arial,Verdana, Helvetica, sans-serif; font-size:11px; color:#006699;font-weight:400;text-decoration:underline" onclick=show_all_friends(\"'+c+'\")>show all</a></td></tr><tr><td colspan="2" style="height:3px"></td></tr><tr><td align="left" colspan="2"><div id="slider" style="display:none"><div id="getimages"  style="font-family:Arial, Helvetica, sans-serif;font-size:11px;border:thin #DDDDDD solid;height:250px;width:570px;overflow-x:hidden;overflow-y:scroll;position:relative;"></div></div></td></tr><tr><td align="left" colspan="2"><div id="selected_list" style="display:none"></div></td></tr></table></div>';
	}
	if(c=='invitefriends')
	{
		document.getElementById('search').style.display='none';
	}
	FriendsSlider(0,c);
}
function clear_search()
{
	document.getElementById('search').value="";
	document.getElementById('search').focus();
}
function FriendsSlider(id,c,invited_id) 
{
	var html_tbl='';
	document.getElementById('show_all').style.display='none';
	if(typeof(invited_id)!='undefined')
	{
		html_tbl=dispImages(id,c,invited_id);		
	}
	else
	{
		html_tbl=dispImages(id,c);		
	}
	if(names_arr.length==0)
	{
		if(c=='search' || c=='slider')
		{
			html_tbl="<table><tr><td align='center' style='font-family:Arial, Helvetica, sans-serif;font-size:11px'>All friends are selected.</td></tr></table>";	
		}
	}
	if(document.getElementById('getimages'))
	{
		document.getElementById('slider').style.display='block';
		document.getElementById('getimages').innerHTML = html_tbl;
	}
	adjustPageHeight();
}
  
function dispImages(id,c,invited_id)
{
	var content="<table style='height:auto;width:auto;border:0px solid #000000'><tr><td colspan='7'><table style='height:auto;width:auto;border:0px solid #000000'>";
	var i=id;
	var row_count=0;
	if(c=='slider')
	{
		if(ids_arr.length>0)
		{
			while(i<ids_arr.length)
			{
				content+='<tr>';
				for (var j=0;j<per_row;j++)
				{		
					if(i<(ids_arr.length))
					{	
						for(var k=0;k<id_string.length;k++)
						{
							if(id_string[k]==ids_arr[i])
							{
								row_count++;
								content+='<td style="height:75px;width:80px;border:0px #cccccc solid" align="center" valign="middle" ><table onclick="remove_friend(\''+escape(name_string[k])+'\',\''+id_string[k]+'\',\''+tid_string[k]+'\',\''+param+'\',\''+c+'\',this.id)" id="'+i+'" style="width: 66px; height:64px; vertical-align:middle;border:0px #cccccc solid;background-image:url('+appPageURL+'/images/selected_bg_new00.gif);" cellpadding="0" cellspacing="0"><tr><td border="0px"  valign="middle" align="center"><img id="img'+i+'" title="'+name_string[k]+'" style="width: 50px; height:45px;border-width:0px; cursor: pointer;" src="'+tid_string[k]+'"/></td></tr></table></td>';
							}
						}
						if(row_count!=1)
						{
							content+='<td style="height:75px;width:80px;border:0px solid #000000" align="center" valign="middle"><div id="div'+i+'" style="width: 63px; height:57px; vertical-align:middle; border: 0px solid rgb(0, 0, 0);padding-bottom:0px; padding-left:5px; padding-right:5px; padding-top:5px;" align="center"><a id="'+i+'" onmouseover=hilight(this.id,"notsel") onmouseout=delight(this.id,"notsel") href="javascript:void(0);" onclick="select_friend(\''+ escape(names_arr[i])+'\',\''+i+'\',\''+ids_arr[i]+'\',\''+tid_arr[i]+'\',\'slider\',this.id)" title="'+names_arr[i]+'" style="left: 2px; top: 5px; z-index: 60;text-decoration:none;border:0px ffffff solid"><table id="tb'+i+'" style="width: 58px; height:50px;border:1px solid #c0c0c0; vertical-align:middle; background-color:#FFFFFF" align="center"><tr><td><img id="img'+i+'" title="'+names_arr[i]+'" style="width: 50px; height:42px;border-width:0px; cursor: pointer;" src="'+tid_arr[i]+'" /></td></tr></table></a></div></td>';
						}
						row_count=0;
					}
					i++;
				}			
				content+='</tr>';
			}
			content+="</table></td></tr>";		
		}
	}
	else if(c=='search')
	{
		document.getElementById('show_all').style.display='block';
		while(i<ids.length)
		{
			content+='<tr>';
			for (var j=0;j<per_row;j++)
			{		
				if(i<(ids.length))
				{		
					for(var k=0;k<id_string.length;k++)
					{
						if(id_string[k]==ids[i])
						{
							row_count++;
							content+='<td style="height:75px;width:80px;border:0px #cccccc solid" align="center" valign="middle" ><table onclick="remove_friend(\''+escape(name_string[k])+'\',\''+id_string[k]+'\',\''+tid_string[k]+'\',\''+param+'\',\''+c+'\',this.id)" id="'+i+'" style="width: 66px; height:64px; vertical-align:middle;border:0px #cccccc solid;background-image:url('+appPageURL+'/images/selected_bg_new00.gif);" align="center"><tr><td border="1px" valign="middle" align="center"><img id="img'+i+'" title="'+name_string[k]+'" style="width: 50px; height:45px;border-width:0px; cursor: pointer;" src="'+tid_string[k]+'"/></td></tr></table></td>';
							//content+='<td style="height:65px;width:70px;" align="center" valign="middle"><div id="div'+i+'" style="width: 63px; height:57px; vertical-align:middle;padding-bottom:0px; padding-left:5px; padding-right:5px; padding-top:5px;" align="center"><a id="'+i+'"  href="javascript:void(0);"  onclick="remove_friend(\''+escape(name_string[k])+'\',\''+id_string[k]+'\',\''+tid_string[k]+'\',\''+param+'\',\''+c+'\',this.id)" title="'+name_string[k]+'" style="left: 2px; top: 5px; z-index: 60;text-decoration:none"><table id="tb'+i+'" style="width: 54px; height:54px;vertical-align:middle; background-image:url('+appPageURL+'/images/selected_bg_new.gif)" align="center"><tr><td valign="top"><img id="img'+i+'" title="'+name_string[k]+'" style="width: 48px; height:42px;border-width:0px; cursor: pointer;background-color:#ffffff" src="'+tid_string[k]+'"/></td></tr></table></a><div></td>';
						}
					}
					if(row_count!=1)
					{
						content+='<td style="height:75px;width:80px;" align="center" valign="middle"><div id="div'+i+'" style="width: 63px;height:57px; vertical-align:middle; border: 0px solid rgb(0, 0, 0);padding-bottom:0px; padding-left:5px; padding-right:5px; padding-top:5px;" align="center"><a id="'+i+'"  onmouseover=hilight(this.id,"notsel") onmouseout=delight(this.id,"notsel") href="javascript:void(0);" onclick="select_friend(\''+ escape(n[i])+'\',\''+i+'\',\''+ids[i]+'\',\''+tids[i]+'\',\'search\',this.id)" title="'+n[i]+'" style="z-index: 60;text-decoration:none"><table id="tb'+i+'" style="width: 58px; height:50px;border:1px solid #c0c0c0; vertical-align:middle; background-color:#FFFFFF" align="center"><tr><td><img id="img'+i+'" title="'+n[i]+'" style="width: 50px; height: 42px;border-width:0px; cursor: pointer;" src="'+tids[i]+'" /></td></tr></table></a></div></td>';//<span id="sp'+i+'" style="display:none;background-color:#FFFFFF;width:inherit">'+n[i].toLowerCase()+'</span>
					}
					row_count=0;
				}
				i++;
			}			
			content+='</tr>';
		}
		
		content+='</table></td></tr>';
	}
	else if(c=='invitefriends')
	{
		if(has_noapp_id.length>0)
		{
			while(i<has_noapp_id.length)
			{
				content+='<tr>';
				for (var j=0;j<per_row;j++)
				{		
					if(i<(has_noapp_id.length))
					{	
						if(has_noapp_id[i]==invited_id)
						{
							content+='<td style="height:65px;width:70px;" align="center" valign="middle"><div id="div'+i+'" style="width: 63px; height:57px; vertical-align:middle;padding-bottom:0px; padding-left:5px; padding-right:5px; padding-top:5px;" align="center"><a id="'+i+'" onmouseover=hilight(this.id,"notsel") onmouseout=delight(this.id,"notsel") href="javascript:void(0);" title="'+has_noapp_name[i]+'" style="left: 2px; top: 5px; z-index: 60;text-decoration:none;cursor:default;"><table id="tb'+i+'" style="width: 52px; height:46px;border:1px solid #c0c0c0; vertical-align:middle; background-color:#FFFFFF" align="center"><tr><td><img id="img'+i+'" title="'+has_noapp_name[i]+'" style="width: 48px; height:42px;border-width:0px; cursor: pointer;" src="'+has_noapp_thumb[i]+'" alt=""/></td></tr></table><span id="invite_msg'+i+'" style="display:none; font:normal 8px Arial">sent!</span></a></div></td>';
						}
						else
						{
							content+='<td style="height:65px;width:70px;" align="center" valign="middle"><div id="div'+i+'" style="width: 63px; height:57px; vertical-align:middle; border: 0px solid rgb(0, 0, 0);padding-bottom:0px; padding-left:5px; padding-right:5px; padding-top:5px;" align="center"><a id="'+i+'" onmouseover=hilight(this.id,"notsel") onmouseout=delight(this.id,"notsel") href="javascript:void(0);" onclick="requestSendMessage(\''+ escape(has_noapp_name[i])+'\',\''+has_noapp_id[i]+'\',\''+has_noapp_thumb[i]+'\')" title="'+has_noapp_name[i]+'" style="left: 2px; top: 5px; z-index: 60;text-decoration:none"><table id="tb'+i+'" style="width: 52px; height:46px;border:1px solid #c0c0c0; vertical-align:middle; background-color:#FFFFFF" align="center"><tr><td><img id="img'+i+'" title="'+has_noapp_name[i]+'" style="width: 48px; height:42px;border-width:0px; cursor: pointer;" src="'+has_noapp_thumb[i]+'"/></td></tr></table></a></div></td>';
						}
					}
					i++;
				}			
				content+='</tr>';
			}
			content+="</table></td></tr>";		
		}
	}
	
	content+="</table>";
	return content;
}
function search_friends(c)
{
	n=new Array();
	ids=new Array();
	tids=new Array();
	val=document.getElementById('search').value;
	var l=val.length;
	var code =val.charCodeAt(0);
	var nme=0;
	if(val!="")
	{
		if(c=='invitefriends')
		{
			for(var i=0;i<has_noapp_name.length;i++)
			{
				if(l>1)
				{
					for(var j=1;j<l;j++)
					{
						var a=val.slice(j,j+1);
						if(val.toUpperCase().slice(0,j)+a.toUpperCase()+val.toUpperCase().slice(j+1,l)==has_noapp_name[i].slice(0,l).toUpperCase())
						{
							if(nme==0)
							{
								n.push(has_noapp_name[i]);
								ids.push(has_noapp_id[i]);
								tids.push(has_noapp_thumb[i]);
							}
							nme++;
						}
						
					}
				}
				else
				{
					var x=has_noapp_name[i].split('');
					var cnt=0;
					var tot_name="";
					if(val.charCodeAt(0)>122 || val.charCodeAt(0)<97)
					{
						for(var y=0;y<x.length;y++)
						{
							if(unescape(val.toLowerCase())==unescape(x[0].toLowerCase()) && cnt==0)
							{
								cnt++;
								tot_name+="<b><font color='black'>"+x[y]+"</font></b>";
							}
							else if(x[y]==' ')
							{
								if(val.toLowerCase()==x[y+1].toLowerCase() && cnt==0)
								{
									cnt++;
									tot_name+=x[y]+"<b><font color='black'>"+x[y+1]+"</font></b>";
									y=y+1;
								}	
								else
								{
									tot_name+=x[y];
								}
							}
							else
							{
								tot_name+=x[y];
							}
												
							if((y+1)==x.length && cnt>0)
							{
								n.push(has_noapp_name[i]);
								ids.push(has_noapp_id[i]);
								tids.push(has_noapp_thumb[i]);
							}
						}
					}
					else if(val.charCodeAt(0)<122 && val.charCodeAt(0)>96)
					{
						for(var y=0;y<x.length;y++)
						{
							if(val.toUpperCase()==x[0].toUpperCase() && cnt==0)
							{
								cnt++;
								tot_name+="<b><font color='black'>"+x[y]+"</font></b>";
							}
							else if(x[y]==' ')
							{
								
								if(val.toUpperCase()==x[y+1].toUpperCase()  && cnt==0)
								{
									cnt++;
									tot_name+=x[y]+"<b><font color='black'>"+x[y+1]+"</font></b>";
									y=y+1;
								}
								else
								{
									tot_name+=x[y];
								}
							}
							else 
							{
								tot_name+=x[y];
							}
							
							if((y+1)==x.length && cnt>0)
							{
								n.push(has_noapp_name[i]);
								ids.push(has_noapp_id[i]);
								tids.push(has_noapp_thumb[i]);
							}
						}
					}
				}
				nme=0;
			}
				
		}
		else
		{
			for(var i=0;i<names_arr.length;i++)
			{
				if(l>1)
				{
					for(var j=1;j<l;j++)
					{
						var a=val.slice(j,j+1);
						if(val.toUpperCase().slice(0,j)+a.toUpperCase()+val.toUpperCase().slice(j+1,l)==names_arr[i].slice(0,l).toUpperCase())
						{
							if(nme==0)
							{
								n.push(names_arr[i]);
								ids.push(ids_arr[i]);
								tids.push(tid_arr[i]);
							}
							nme++;
						}
						
					}
				}
				else
				{
					var x=names_arr[i].split('');
					var cnt=0;
					var tot_name="";
					if(val.charCodeAt(0)>122 || val.charCodeAt(0)<97)
					{
						for(var y=0;y<x.length;y++)
						{
							if(unescape(val.toLowerCase())==unescape(x[0].toLowerCase()) && cnt==0)
							{
								cnt++;
								tot_name+="<b><font color='black'>"+x[y]+"</font></b>";
							}
							else if(x[y]==' ')
							{
								if(val.toLowerCase()==x[y+1].toLowerCase() && cnt==0)
								{
									cnt++;
									tot_name+=x[y]+"<b><font color='black'>"+x[y+1]+"</font></b>";
									y=y+1;
								}	
								else
								{
									tot_name+=x[y];
								}
							}
							else
							{
								tot_name+=x[y];
							}
												
							if((y+1)==x.length && cnt>0)
							{
								n.push(names_arr[i]);
								ids.push(ids_arr[i]);
								tids.push(tid_arr[i]);
							}
						}
					}
					else if(val.charCodeAt(0)<122 && val.charCodeAt(0)>96)
					{
						for(var y=0;y<x.length;y++)
						{
							if(val.toUpperCase()==x[0].toUpperCase() && cnt==0)
							{
								cnt++;
								tot_name+="<b><font color='black'>"+x[y]+"</font></b>";
							}
							else if(x[y]==' ')
							{
								
								if(val.toUpperCase()==x[y+1].toUpperCase()  && cnt==0)
								{
									cnt++;
									tot_name+=x[y]+"<b><font color='black'>"+x[y+1]+"</font></b>";
									y=y+1;
								}
								else
								{
									tot_name+=x[y];
								}
							}
							else 
							{
								tot_name+=x[y];
							}
							
							if((y+1)==x.length && cnt>0)
							{
								n.push(names_arr[i]);
								ids.push(ids_arr[i]);
								tids.push(tid_arr[i]);
							}
						}
					}
				}
				nme=0;
			}
		}
		if(n.length>0)
		{
			FriendsSlider(0,c);
		}
		else
		{
			if(val!=search_msg)
			{
				if(document.getElementById('getimages'))
				{
					document.getElementById('slider').style.display='block';
					document.getElementById('getimages').innerHTML="<table style='height:auto;width:auto'><tr><td colspan='7'><table style='height:auto;width:auto'><tr><td style='padding-left:10px'>No friends</td></tr></table></td></tr></table>";
				}
			}
		}
	}
	adjustPageHeight();
}
function select_friend(name,c_id,id,tid,context)
{
	for(var j=0;j<name_string.length;j++)
	{
		if(name_string[j]==(unescape(name)))
		{
			name_string.splice(j,1);
			id_string.splice(j,1);
			tid_string.splice(j,1);
		}
	}
	/*if(context!='invitefriends')
	{
		for(var j=0;j<names_arr.length;j++)
		{
			if(names_arr[j]==unescape(name))
			{
				ids_arr.splice(j,1);
				tid_arr.splice(j,1);
				names_arr.splice(j,1);
			}
		}
		
	}*/
	name_string.push(unescape(name));
	id_string.push(id);
	tid_string.push(tid);
	/*var main_tbl="";
	var content="<table>";
	var i=0;
	if(name_string.length>0)
	{
		while(i<(name_string.length))
		{
			content+='<tr>';
			for (var j=0;j<5;j++)
			{				
				if(i<(name_string.length))
				{		
					content+="<td align='left' valign='middle' style='background-color:#ecf4fd;height:100%;width:100px'><table><tr><td align='center' valign='middle' style='background-color:white;width:90%;height:100%;font-size:11px'><img src='" + tid_string[i] + "' style='border-color:#999999;border-width:1px' width='48px' height='42px'/><br/><font style='font-size:11px;color:#000000'>"+name_string[i].toLowerCase().substring(0,7)+"...</font></td><td valign='top' align='center' style='width:10%'><a href='javascript:void(0);' onclick=\"remove_friend('"+escape(name_string[i])+"','"+id_string[i]+"','"+tid_string[i]+"','create','"+context+"')\"><img src='"+appPageURL+"/images/cancel.gif' border='0'/></a></td></table></td>";
				}
				i++;
			}			
			content+='</tr>';
		}
		content+="</table>";		
	}
	main_tbl+=content;
	*/
	if(context=='search')
	{
		document.getElementById('search').value=val;
	}
	else
	{
		document.getElementById('search').value=search_msg;
	}
	FriendsSlider(0,context);
	document.getElementById('search').focus();
	/*document.getElementById('selected_list').style.display='block';
	document.getElementById('selected_list').innerHTML=main_tbl;
	
	main_tbl="";*/
}
function remove_friend(nme,uid,tbid,context_pg,context)
{
	if(nme!='')
	{
		if(context_pg=='edit')
		{		
			for(var c=0;c<canceluids.length;c++)
			{
				if(canceluids[c]==uid)
				{
					canceluids.splice(c,1);						
				}										   
			}
		}
		/*if(context!='invitefriends')
		{
			names_arr.push(unescape(nme));
			ids_arr.push(uid);
			tid_arr.push(tbid);
		}*/
		for(var j=0;j<name_string.length;j++)
		{
			if(name_string[j]==unescape(nme))
			{	
				name_string.splice(j,1);
				id_string.splice(j,1);
				tid_string.splice(j,1);
				
			}
		}
				/*var main_tbl="";
				var content="<table height='30px' width:'100px' >";
				var i=0;
				if(name_string.length>0)
				{
					while(i<(name_string.length))
					{
						content+='<tr>';
						for (var j=0;j<5;j++)
						{				
							if(i<(name_string.length))
							{		
								content+="<td align='left' valign='middle' style='background-color:#ecf4fd;height:100%;width:100px'><table><tr><td align='center' valign='middle' style='background-color:white;width:90%;height:100%;font-size:11px'><img src='" + tid_string[i] + "' style='border-color:#999999;border-width:1px' width='48px' height='42px'/><br/><font style='font-size:11px;color:#000000'>"+name_string[i].toLowerCase().substring(0,7)+"...</font></td><td valign='top' align='center' style='width:10%'><a href='javascript:void(0);' onclick=\"remove_friend('"+escape(name_string[i])+"','"+id_string[i]+"','"+tid_string[i]+"','"+context_pg+"','"+context+"')\"><img src='"+appPageURL+"/images/cancel.gif' border='0'/></a></td></table></td>";
							}
							i++;
						}			
						content+='</tr>';
					}
					content+="</table>";		
				}
				else
				{
					content+='<tr><td></td><tr></table>';
				}
				main_tbl+=content;
				search_friends(context);*/
					
		
			//search_friends(context);
			FriendsSlider(0,context);
				
		/*document.getElementById('selected_list').style.display='block';
		document.getElementById('selected_list').innerHTML=main_tbl;*/
		if(val!='')
		{
			document.getElementById('search').value=val;
		}
		else
		{
			document.getElementById('search').value=search_msg;
		}
		document.getElementById('search').focus();
				//main_tbl="";
	}
	else
	{
			
	}
	adjustPageHeight();
}

function hilight(id,con)
{
	/*if(con!='sel')
	{*/
		/*document.getElementById('div'+id).style.paddingTop='2px';
		document.getElementById('div'+id).style.paddingBottom='0px';
		document.getElementById('tb'+id).style.width='60px';
		document.getElementById('tb'+id).style.height='58px';
		document.getElementById('img'+id).style.width='48px';
		document.getElementById('img'+id).style.height='42px';
		document.getElementById('div'+id).style.paddingRight='2px';
		document.getElementById('div'+id).style.paddingLeft='2px';
		*/
		document.getElementById('div'+id).style.paddingTop='2px';
		document.getElementById('div'+id).style.paddingBottom='0px';
		document.getElementById('tb'+id).style.width='62px';
		document.getElementById('tb'+id).style.height='54px';
		document.getElementById('img'+id).style.width='54px';
		document.getElementById('img'+id).style.height='46px';
	/*}
	else
	{
		document.getElementById('div'+id).style.paddingTop='2px';
		document.getElementById('div'+id).style.paddingBottom='0px';
		document.getElementById('tb'+id).style.backgroundColor='#000000';
		document.getElementById('tb'+id).style.width='62px';
		document.getElementById('tb'+id).style.height='54px';
		document.getElementById('img'+id).style.width='60px';
		document.getElementById('img'+id).style.height='52px';
		if(document.getElementById('invite_msg'+id))
		{
			document.getElementById('invite_msg'+id).style.display='block';
		}
	}*/
}

function delight(id,con)
{
	/*if(con!='sel')
	{*/
		document.getElementById('div'+id).style.paddingRight='5px';
		document.getElementById('div'+id).style.paddingLeft='5px';
		document.getElementById('div'+id).style.paddingTop='5px';
		document.getElementById('div'+id).style.paddingBottom='0px';
		document.getElementById('tb'+id).style.width='58px';
		document.getElementById('tb'+id).style.height='50px';
		document.getElementById('img'+id).style.width='50px';
		document.getElementById('img'+id).style.height='42px';
	/*}
	else
	{
		document.getElementById('div'+id).style.paddingRight='5px';
		document.getElementById('div'+id).style.paddingLeft='5px';
		document.getElementById('div'+id).style.paddingTop='5px';
		document.getElementById('div'+id).style.paddingBottom='0px';
		document.getElementById('tb'+id).style.width='58px';
		document.getElementById('tb'+id).style.height='50px';
		document.getElementById('tb'+id).style.backgroundColor='#000000';
		document.getElementById('img'+id).style.width='50px';
		document.getElementById('img'+id).style.height='42px';
		if(document.getElementById('invite_msg'+id))
		{
			document.getElementById('invite_msg'+id).style.display='block';
		}
	}*/
}

function show_all_friends(c)
{
	document.getElementById('search').value=search_msg;
	FriendsSlider(0,c);	
}

/*function search_slider(no)
{
	var main_tbl="<table style='height:auto;width:auto'>";
	var content="<tr><td><table style='height:auto;width:auto'>";
	var i=no;
	var row_count=0;
	var up_arrow='';
	var down_arrow='';
	document.getElementById('show_all').style.display='block';
	while(i<ids.length)
	{
		content+='<tr>';
		for (var j=0;j<per_row;j++)
		{		
			if(i<(ids.length))
			{		
				content+='<td style="height:auto;width:auto" align="center" valign="middle"><div id="div'+i+'" style="width: 62px;height:57px; vertical-align:middle; border: 0px solid rgb(0, 0, 0);padding-bottom:0px; padding-left:5px; padding-right:5px; padding-top:5px;" align="center"><a id="'+i+'"  onmouseover="hilight(this.id);" onmouseout="delight(this.id);" href="javascript:void(0);" onclick="select_friend(\''+ escape(n[i])+'\',\''+ids[i]+'\',\''+tids[i]+'\',\'search\',this.id)" title="'+n[i]+'" style="z-index: 60;text-decoration:none"><table id="tb'+i+'" style="width: 52px; height:46px;border:1px solid #c0c0c0; vertical-align:middle; background-color:#FFFFFF" align="center"><tr><td><img id="img'+i+'" title="'+n[i]+'" style="width: 48px; height: 42px;border-width:0px; cursor: pointer;" src="'+tids[i]+'" alt=""/></td></tr></table><span id="sp'+i+'" style="display:none;background-color:#FFFFFF;width:inherit">'+n[i].toLowerCase()+'</span></a></div></td>';
			}
			i++;
		}			
		content+='</tr>';
	}
	
	content+='</table></td></tr>';
	main_tbl+=up_arrow+content+down_arrow+"</table>";	
	return main_tbl;	
}*/
 
/*function MoveUpInvitees(i_up,context)
{
	i_up=i_up-per_row;
	FriendsSlider(i_up,context);
}
	
function MoveDownInvitees(i_down,context)
{
	FriendsSlider(i_down,context); 
}
*/



function clear_ddl(e)
{
	var targ;
	
	if (!e)
	{
	  var ex=window.event;
	}
	if (e.target)
	{
	  targ=e.target;
	}
	else if (e.srcElement)
	{
	  targ=e.srcElement;
	}
	if (targ.nodeType==3) // defeat Safari bug
	{
	  targ = targ.parentNode;
	}
	var tname;
	tname=targ.tagName;
	if(tname!='INPUT')
	{
		document.getElementById('search').value=search_msg;
		/*if(document.getElementById('color_pallete'))
		{
			document.getElementById('color_pallete').style.display='none';	
		}*/
		
	}
}

////////special characters validation////////////////
var iChars=new Array("'","\\");
function specialchar(val)
{
	var arr=new Array();
	
	for (var i = 0; i < val.length; i++) 
	{
		var s=val.charAt(i);
		if (iChars[0].indexOf(val.charAt(i)) != -1) 
		{
			
			arr[i]=s;
			
		}
		else
		{
			arr[i]=s;
		}
    }
	return arr;
}

function encode_text(val)
{
	var arr=new Array();
	var r="";
	arr=specialchar(val);
	for (var i = 0; i < arr.length; i++) 
	{
		if(arr[i]=="'" || arr[i]=="\\" || arr[i]=="$")
		{
			r+="\\"+arr[i];
		}
		else
		{
			r+=arr[i];
		}
	}
	return r;
}

function decode_text(val)
{
	var res="";
	for (var i = 0; i < val.length; i++) 
	{
		
		if (iChars[1].indexOf(val.charAt(i)) == -1) 
		{
			var s=val.charAt(i);
			res+=s;
		}
    }
	return res;
}

function Show_friends()
{
	
	/*var cancelled_ids="<table height='30px' width:'100px' ><tr>";
	for(var cancel_ind=0;cancel_ind<canceluids.length;cancel_ind++)
	{
		for(var ind=1;ind<puid_arr.length;)
		{
			if(cancel_ind % 4==3)
			{
				if(canceluids[cancel_ind]==	puid_arr[ind] && ind < puid_arr.length)
				{
					cancelled_ids+="<td align='left' valign='middle' style='background-color:#ecf4fd;height:100%;width:100px'><table><tr><td style='background-color:white;width:90%;height:100%;font-size:9px'><img src='" + thumb_arr[ind] + "' class='photoborder'/><br/>"+pname_arr[ind].toLowerCase().substring(0,7)+"...</td><td valign='top' align='center' style='width:10%'><a href='javascript:void(0);' onclick=\"remove_friend('"+escape(pname_arr[ind])+"','"+puid_arr[ind]+"','"+thumb_arr[ind]+"','edit','slider')\"><img src='"+appPageURL+"/images/cancel.gif' border='0'/></a></td></table></td></tr><tr>";
					name_string.push(pname_arr[ind]);
					id_string.push(puid_arr[ind]);
					tid_string.push(thumb_arr[ind]);
					
				}
				ind++;
			}
			else
			{
				if(canceluids[cancel_ind]==	puid_arr[ind] && ind < puid_arr.length)
				{
					cancelled_ids+="<td align='left' valign='middle' style='background-color:ecf4fd;height:100%;width:100px'><table><tr><td style='background-color:white;width:90%;height:100%;font-size:9px'><img src='" + thumb_arr[ind] + "' class='photoborder'/><br/>"+pname_arr[ind].toLowerCase().substring(0,7)+"...</td><td valign='top' align='center' style='width:10%'><a href='javascript:void(0);' onclick=\"remove_friend('"+escape(pname_arr[ind])+"','"+puid_arr[ind]+"','"+thumb_arr[ind]+"','edit','slider')\"><img src='"+appPageURL+"/images/cancel.gif' border='0'/></a></td></table></td>";
					name_string.push(pname_arr[ind]);
					id_string.push(puid_arr[ind]);
					tid_string.push(thumb_arr[ind]);
					
				}
				ind++;
			}
		}
	}
	cancelled_ids+="</table>";
	document.getElementById('selected_list').style.display='block';
	document.getElementById('selected_list').innerHTML=cancelled_ids;*/
}
/////////////////end of special character validation/////////////////////
var btn_click=0;
function PostHangoutData(pg) 
{
	var datecompare ='';
	var return_create="";
	var return_edit="";
	if(pg=='create')
	{

		param = 'create';
		var _htitle=document.getElementById('htitle').value;
		var _sdate=document.getElementById('sdate').value;
		var _hothertype=document.getElementById('hothertype').value;
		var _stime=document.getElementById('stime').value;
		var _edate=document.getElementById('edate').value;
		var _etime=document.getElementById('etime').value;
		var _allday=document.getElementById('AllDay');
		_address=document.getElementById('vaddress1').value;
		var _street=document.getElementById('vstreet').value;
		var _city=document.getElementById('vcity').value;
		var _htype=document.getElementById('htype').value;
		var _message=document.getElementById('message').value;
		////   statically passing reminder into db
		var _reminder = 1;
		var _hostid=hostid;
		var _uids=id_string;
		var d = new Date();
		current_time = d.getHours()+':'+d.getMinutes();
	// Validations for all fields
		var ht = trimAll(_htitle);
		var ho = trimAll(_hothertype);
		var city = trimAll(_city);
		var addr = trimAll(_address);
		
		if(ht == 0) 
		{
			alert(displayMsg("Enter Hangout Name"));
			document.getElementById('htitle').value = '';
			document.getElementById('htitle').focus();
			return false;
		}
		else if(_htype == 0) 
		{
			alert(displayMsg("Select Hangout Type"));
			//document.getElementById('sdate').focus();
			return false;
		}
		else if(_sdate == '') 
		{
			alert(displayMsg("Enter Start Date"));
			//document.getElementById('sdate').focus();
			return false;
		}
		else if(_edate == '') 
		{
			if(_allday.checked == true) 
			{
				_edate=_sdate;
				_etime='23:30';
				document.getElementById('etime').value='23:30';
				document.getElementById('vaddress1').focus();
				return true;
			}
			else if(_allday.checked == false)
			{
				alert(displayMsg("Enter End Date"));
				//document.getElementById('edate').focus();
				return false;
			
			}
		}
		else if(addr==0) 
		{
			alert(displayMsg("Enter Address"));
			document.getElementById('vaddress1').value = '';
			document.getElementById('vaddress1').focus();
			return false;
		}
		/*else if(_street=='') 
		{
			alert('Enter Street');
			document.getElementById('vstreet').focus();
			return false;
		}*/
		else if(city==0) 
		{
			alert(displayMsg("Enter City"));
			document.getElementById('vcity').value = '';
			document.getElementById('vcity').focus();
			return false;
		}
		else if(_uids == '')
		{
			alert(displayMsg("Select Friends"));
			return false;
		}
		/*else if(_message=='') 
		{
			alert('Enter Message to Guests');
			document.getElementById('message').focus();
			return false;
		}*/
		else if(_htype == 45 && ho == 0)
		{
				alert(displayMsg("Enter Hangout Other Type"));
				document.getElementById('hothertype').value = '';
				document.getElementById('hothertype').focus();
				return false;
			
		}
		else
		{
			datecompare=comparedate();
			return_create=pstdatecompare();	
		}
		
		if(return_create!=false && datecompare != false)
		{
			u=0;
			document.getElementById('btn_create').disabled=true;
			document.getElementById('ld_create').style.display='block';
			_htitle = encode_text(_htitle);
			_address = encode_text(_address);
			_street = encode_text(_street);
			_city = encode_text(_city);
			_message = encode_text(_message);
			_hothertype = encode_text(_hothertype);
			
			if(trimAll(_street) == 0)
			{
				_street = '';
			}
			if(trimAll(_message) == 0)
			{
				_message = '';
			}
			/*if(document.getElementById('defaultloc').checked==true)
			{
				if(_street!='')
				{
					_default_loc=_address+','+_street+','+_city;
				}
				else
				{
					_default_loc=_address+','+_city;
				}
				
			}*/
			var url=appServletURL+'/CreateHangout?'+ urlParams.join('');
			
			var params = {};
			params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
			params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
			//post_params();
			postdata = {    htitle : _htitle,    htype : _htype,    sdate : _sdate,    edate : _edate,    etime : _etime,    stime : _stime,    vaddress1 : _address,    message : _message,    reminder : _reminder,    vstreet : _street,    vcity : _city,    hothertype : _hothertype,    hostid : _hostid,    uids : _uids  ,defaultlocation:_default_loc,token:token};
			params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
			gadgets.io.makeRequest(url,function(response) 
			{
				if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null || response.errors[0]=="Error 400")
				{
					//err_conunt++;
					//if(err_conunt>4)
					//{
						var message = Customized_ErrorMessages('servlet');
						 alert(message);
						 err_conunt=0;
						 document.getElementById('ld_create').style.display='none';
						 document.getElementById('btn_create').disabled=false;
						 return;
					//}
					//else
					//{
					//	PostHangoutData('create');
					//}
				}
				else
				{
					var html = eval('('+response.text+')');  
					if(html.status==1) 
					{
						var url=appServletURL+'/UpdateHangoutAction?'+ urlParams.join('');
						var p = {};
						p[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
						p[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
						p[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
						
						var personlist="";
						for(var i=0;i<_uids.length;i++)
						{
							for(var j=0;j<puid_arr.length;j++)
							{
								if(_uids[i]==puid_arr[j])
								{
									personlist+=puid_arr[j]+"$$$"+escape(pname_arr[j])+"$$$"+thumb_arr[j]+"$$$"+escape(puid_url[j]);
									if(i!=_uids.length-1)
									{
										personlist+=",";
									}
								}
							}
						}
						postdata = {hid : html.hid,uids : personlist,action : 1, hostid: hostid , appid:appId,token:token};
						p[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
						gadgets.io.makeRequest(url,function(response) 
						{
							if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null || response.errors[0]=="Error 400")
							{
								var message = Customized_ErrorMessages('servlet');
								 alert(message);
								 err_conunt=0;
								 document.getElementById('ld_create').style.display='none';
								 document.getElementById('btn_create').disabled=false;
								 return;
							}
							else
							{
								//requestSendMessage('','','');
								postActivity('createhangout',escape(decode_text(_htitle)),html.hid);
								getHtmlPage('th_create','','');
								if(id_string.length>0)
								{
									clearArray(id_string);
								};
								u=0;
								id_string.length=0;
							}
						},p);
					}
					else
					{
						return false;//if the hangout isnt created
						document.getElementById('ld_create').style.display='none';
					}
				}
			},params);		
				
		}
	}
	else if(pg=='edit')
	{
		var _htitle=document.getElementById('edithtitle').value;
		var _sdate=document.getElementById('editsdate').value;
		var _hothertype=document.getElementById('edithothertype').value;
		var _stime=document.getElementById('editstime').value;
		var _edate=document.getElementById('editedate').value;
		var _etime=document.getElementById('editetime').value;
		var _allday=document.getElementById('editAllDay');
		_address=document.getElementById('editvaddress1').value;
		var _street=document.getElementById('editvstreet').value;
		var _city=document.getElementById('editvcity').value;
		var _htype=document.getElementById('edithtype').value;
		var _message=document.getElementById('editmessage').value;
		var _reminder= 1;
		var _hostid=hostid;
		var _uids=id_string;
		var d = new Date();
		current_time = d.getHours()+':'+d.getMinutes();
		var ht = trimAll(_htitle);
		var ho = trimAll(_hothertype);
		var city = trimAll(_city);
		var addr = trimAll(_address);
		if(ht == 0) 
		{
			alert(displayMsg('Enter Hangout Name'));
			document.getElementById('edithtitle').value = '';
			document.getElementById('edithtitle').focus();
			return false;
		}
		else if(_htype == 0) 
		{
			alert(displayMsg('Select Hangout Type'));
			return false;
		}
		else if(_sdate == '') 
		{
			alert(displayMsg('Enter Start Date'));
			return false;
		}
		else if(_edate == '') 
		{
			if(_allday.checked == true) 
			{
				_edate=_sdate;
				_etime='23:30';
				document.getElementById('editetime').value='23:30';
				document.getElementById('editvaddress1').focus();
				return true;
			}
			else if(_allday.checked == false)
			{
				alert(displayMsg('Enter End Date'));
				return false;
			}
		}
		
		else if(addr==0) 
		{
			alert(displayMsg('Enter Address'));
			document.getElementById('editvaddress1').value = '';
			document.getElementById('editvaddress1').focus();
			return false;
		}
		else if(city==0) 
		{
			alert(displayMsg(displayMsg("Enter City")));
			document.getElementById('editvcity').value = '';
			document.getElementById('editvcity').focus();
			return false;
		}
		else if(_uids == '')
		{
			alert(displayMsg("Select Friends"));
			return false;
		}
		else if(_htype == 45 && ho=='')
		{
			if(_hothertype == 0)
			{
				alert(displayMsg('Enter Hangout Other Type'));
				document.getElementById('edithothertype').value = '';
				document.getElementById('edithothertype').focus();
				return false;
			}
		}
		else
		{
			return_edit=pstdatecompare();
			datecompare=comparedate();
		}
		_sdate=document.getElementById('editsdate').value;
		_stime=document.getElementById('editstime').value;
		_edate=document.getElementById('editedate').value;
		_etime=document.getElementById('editetime').value;
		if(canceluids.length==0) 
		{
			canceluids=hostid;	
		}
		if(return_edit==true && datecompare==true)
		{
			if(trimAll(_street) == 0)
			{
				_street = '';
			}
			if(trimAll(_message) == 0)
			{
				_message = '';
			}
			
			document.getElementById('update').disabled=true;
			document.getElementById('ld_edit').style.display='block';
			var params = {};
			params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
			params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;   
			var url=appServletURL+"/UpdateHangoutAction?"+ urlParams.join('');
			//post_params();
			postdata = {    hid : jsonvar.HangoutID,    uids : canceluids,    action : 5 , hostid: hostid , appid:appId , token:token };
			params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);

			gadgets.io.makeRequest(url,function(response) 
			{
				if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null || response.errors[0]=="Error 400")
				{
					var message = Customized_ErrorMessages('servlet');
					 alert(message);
					 err_conunt=0;
					 document.getElementById('ld_edit').style.display='none';
					 document.getElementById('update').disabled=false;
					 return;
				}
				else
				{
					var edited = eval('('+response.text+')'); 
					if(edited.status==1) 
					{
						_htitle = encode_text(_htitle);
						_address = encode_text(_address);
						_street = encode_text(_street);
						_city = encode_text(_city);
						_message = encode_text(_message);
						_hothertype = encode_text(_hothertype);
						/*if(document.getElementById('defaultloc').checked==true)
						{
							if(_street!='')
							{
								_default_loc=_address+','+_street+','+_city;
							}
							else
							{
								_default_loc=_address+','+_city;
							}
						}*/
						var url=appServletURL+'/CreateHangout?'+ urlParams.join('');
						postdata = {htitle : _htitle,    htype : _htype,    sdate : _sdate,    edate : _edate,    etime : _etime,    stime : _stime,    vaddress1 : _address,    message : _message,    reminder : _reminder,    vstreet : _street,    vcity : _city,    hothertype : _hothertype,    hostid : _hostid,    uids : _uids,defaultlocation: _default_loc,token:token };
						params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
						gadgets.io.makeRequest(url,function(response1) 
						{	
							if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
							{
								//err_conunt++;
								//if(err_conunt>4)
								//{
									var message = Customized_ErrorMessages('servlet');
									 alert(message);
									 err_conunt=0;
									 document.getElementById('ld_edit').style.display='none';
									 document.getElementById('update').disabled=false;
									 return;
								//}
								//else
								//{
								//	PostHangoutData('edit');
								//}
							}
							else
							{
								var html1 = eval('('+response1.text+')');  
								if(html1.status==1) 
								{
									var url=appServletURL+'/UpdateHangoutAction?'+ urlParams.join('');
									var params = {};
									params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
									params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
									params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
									var personlist="";
									for(var i=0;i<_uids.length;i++)
									{
										for(var j=0;j<puid_arr.length;j++)
										{
											if(_uids[i]==puid_arr[j])
											{
												personlist+=puid_arr[j]+"$$$"+escape(pname_arr[j])+"$$$"+thumb_arr[j]+"$$$"+escape(puid_url[j]);
												if(i!=_uids.length-1)
												{
													personlist+=",";
												}
											}
										}
									}
									postdata = {hid : html1.hid,uids : personlist,action : 1, hostid: hostid , appid:appId , token:token};
									params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
									gadgets.io.makeRequest(url,function(response) 
									{
										if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
										{
											//err_conunt++;
											//if(err_conunt>4)
											//{
												var message = Customized_ErrorMessages('servlet');
												 alert(message);
												 err_conunt=0;
												 document.getElementById('ld_edit').style.display='none';
												 document.getElementById('update').disabled=false;
												 return;
											//}
											//else
											//{
											//	PostHangoutData('edit');
											//}
										}
										else
										{
											//updating media data
											var html = eval('('+response1.text+')');  
											if(html.status==1) 
											{
											
												var m='';
												if(jsonvar.PhotoLinks!='' && typeof(jsonvar.PhotoLinks)!='undefined')
												{
													var media_photos='';
													for(var i=0;i<jsonvar.PhotoLinks.length;i++)
													{
														media_photos+=jsonvar.PhotoLinks[i].title+"$$$"+jsonvar.PhotoLinks[i].url+",";
													}
													postdata={hid : html1.hid,uids : hostid,action : 6,media : media_photos, hostid: hostid , appid:appId , token:token};
													var url=appServletURL+'/UpdateHangoutAction?'+ urlParams.join('');
													var params = {};
													params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
													params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
													params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
													params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;   
													params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
													gadgets.io.makeRequest(url,function(response) 
													{
														if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
														{
															//err_conunt++;
															//if(err_conunt>4)
															//{
																var message = Customized_ErrorMessages('servlet');
																 alert(message);
																 err_conunt=0;
																 document.getElementById('ld_edit').style.display='none';
																 document.getElementById('update').disabled=false;
																 return m=false;
															//}
															//else
															//{
															//	PostHangoutData('edit');
															//}
															
														}
														else
														{
															return m=true;	
														}
														
													},params);
												}
												
												if(jsonvar.VideoLinks!='' && typeof(jsonvar.VideoLinks)!='undefined')
												{
													var media_videos='';
													for(var i=0;i<jsonvar.VideoLinks.length;i++)
													{
														media_videos+=jsonvar.VideoLinks[i].title+"$$$"+jsonvar.VideoLinks[i].url+",";
													}
													postdata = {hid : html1.hid,uids : hostid,action :7,media : media_videos, hostid: hostid , appid:appId , token:token};
													var url=appServletURL+'/UpdateHangoutAction?'+ urlParams.join('');
													var params = {};
													params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
													params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
													params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
													params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;   
													params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
													gadgets.io.makeRequest(url,function(response) 
													{
														if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
														{
															//err_conunt++;
															//if(err_conunt>4)
															//{
																var message = Customized_ErrorMessages('servlet');
																 alert(message);
																 err_conunt=0;
																 document.getElementById('ld_edit').style.display='none';
																 document.getElementById('update').disabled=false;
																 return m=false;
															//}
															//else
															//{
															//	PostHangoutData('edit');
															//}
														}
														else
														{
															return m=true;	
														}
														
													},params);
												}
												getHtmlPage('th_edit','','');
												u=0;
											}
										}
									},params);
								}
								else
								{
									document.getElementById('ld_edit').style.display='none';	
								}
							}
						},params);//hangout updation
					
					}
				}
			},params);	//cancelling the hangout
		}
	}
}
	////////////////// -------- Past Date Comparision ----------////////////////////////
function pstdatecompare() 
{
	var _sdate;
	var _stime;
	var _etime;
	var current_time;
	if(param=='edit')
	{
		_sdate= document.getElementById('editsdate').value;
		_stime=document.getElementById('editstime').value;
		_etime=document.getElementById('editetime').value;
		_edate= document.getElementById('editedate').value;
	}
	else
	{
		_sdate= document.getElementById('sdate').value;
		_stime=document.getElementById('stime').value;
		_etime=document.getElementById('etime').value;
		_edate= document.getElementById('edate').value;
	}
	var year;
	if(_sdate != '' ) 
	{ 
		var d = new Date();
		current_time=d.getHours()+":"+d.getMinutes();
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			today = d.getMonth()+1+'/'+d.getDate()+'/'+d.getYear();
		}
		else
		{
			year=d.getYear()+1900;	
			today = d.getMonth()+1+'/'+d.getDate()+'/'+year;
		}
		
		var a=today.split('/');
		var b=_sdate.split('/');
		var c=_edate.split('/');
		var x=_stime.split(':');
		var y=_etime.split(':');
		
		if(Date.parseString(_sdate).isAfter(Date.parseString(today)) || Date.parseString(_sdate).equals(Date.parseString(today))) 
		{
			if(_edate!='')
			{
				if(Date.parseString(_sdate).equals(Date.parseString(today)) && Date.parseString(_edate).equals(Date.parseString(today)))
				{
					if((Date.UTC(a[2],a[0],a[1],d.getHours(),d.getMinutes(),0,0)) >= (Date.UTC(b[2],b[0],b[1],x[0],x[1],0,0)) || (Date.UTC(b[2],b[0],b[1],x[0],x[1],0,0)) >= (Date.UTC(c[2],c[0],c[1],y[0],y[1],0,0)) || (Date.UTC(a[2],a[0],a[1],d.getHours(),d.getMinutes(),0,0)) >= (Date.UTC(c[2],c[0],c[1],y[0],y[1],0,0)))
					{
						alert(displayMsg('Enter valid start and end time.'));
						return false;
					}
					else
					{
						return true;	
					}
				}
				else if(Date.parseString(_sdate).equals(Date.parseString(today)))
				{
					if((Date.UTC(b[2],b[0],b[1],x[0],x[1],0,0)) < (Date.UTC(a[2],a[0],a[1],d.getHours(),d.getMinutes(),0,0)))
					{
						alert(displayMsg('Enter valid Start Time.'));
						return false;
					}
					else
					{
						return true;	
					}	
				}
				else if(Date.parseString(_sdate).equals(Date.parseString(_edate)))
				{
					if((Date.UTC(b[2],b[0],b[1],x[0],x[1],0,0)) >= (Date.UTC(c[2],c[0],c[1],y[0],y[1],0,0)))
					{
						alert(displayMsg('Enter valid start and end time.'));
						return false;
					}
					else
					{
						return true;	
					}
			
				}
				else if(Date.parseString(_sdate).isAfter(Date.parseString(today)))
				{
					if(param!='edit')
					{
						if(document.getElementById('AllDay').checked == true)	
						{
							document.getElementById('edate').value = document.getElementById('sdate').value;
							return true;
						}
						else
						{
							return true;
						}
					}
					else if(param=='edit')
					{
						if(document.getElementById('editAllDay').checked == true)	
						{
							document.getElementById('editedate').value = document.getElementById('editsdate').value;
							return true;
						}
						else
						{
							return true;	
						}
					}
				}
			}
			else
			{
				if(param!='edit')
				{
					if(document.getElementById('AllDay').checked == true)	
					{
						document.getElementById('edate').value = document.getElementById('sdate').value;
						return true;
					}
					else if(document.getElementById('AllDay').checked == false)
					{
						return false;
					}
				}
				else if(param=='edit')
				{
					if(document.getElementById('editAllDay').checked == true)	
					{
						document.getElementById('editedate').value = document.getElementById('editsdate').value;
						return true;
					}
					else if(document.getElementById('editAllDay').checked == false)
					{
						alert(displayMsg("Enter End Date"));
						return false;
					}	
				}
			}
		}
		else
		{
			if(param=='edit')
			{
				document.getElementById('editsdate').value = today;
				return true;
			}
			else
			{
				alert(displayMsg('Start Date Must be today or greater than Today'));
				document.getElementById('sdate').value = '';
				return false;
			}
		}
	}
}	
////////////////// -------- Dates Comparision ----------////////////////////////
function comparedate() 
{
	var _edate;
	var _sdate;
	if(param=='edit') 
	{
		_edate=document.getElementById('editedate').value;
		_sdate=document.getElementById('editsdate').value;
	}
	else 
	{
		_edate=document.getElementById('edate').value;
		_sdate=document.getElementById('sdate').value;
	}
	if(_sdate != '' && _edate != '') 
	{
		if(Date.parseString(_edate).isAfter(Date.parseString(_sdate)) || Date.parseString(_edate).equals(Date.parseString(_sdate))) 
		{
			return true;
		}
		else 
		{
			if(param!='edit')
			{
				if(document.getElementById('AllDay').checked == true)
				{
					document.getElementById('edate').value = document.getElementById('sdate').value;
					return true;
				}
				else
				{
					alert(displayMsg('End Date must be greater than or equal to start date'));
					document.getElementById('edate').value='';
					return false;
				}
			}
			else
			{
				if(document.getElementById('editAllDay').checked == true)
				{
					document.getElementById('editedate').value = document.getElementById('editsdate').value;
					return true;
				}
				else
				{
					alert(displayMsg('End Date must be greater than or equal to start date'));
					document.getElementById('editedate').value='';
					return false;
				}
			}
		}
	}
}
////////////////// --------TextBox for Hangout Other Type----------////////////////////////
function print_value()
 {
	var _type;
	if(param=='edit')
	{
		_type = document.getElementById('edithtype').value;
		if(_type == '45')  
		{
			document.getElementById('edithothertype').style.display = 'block';
			document.getElementById('editchar_other').style.display = 'block';
			document.getElementById('editwarning1').style.display = 'block';
		}
		else 
		{
			document.getElementById('edithothertype').value='';
			document.getElementById('editchar_other').style.display = 'none';
			document.getElementById('edithothertype').style.display = 'none';
			document.getElementById('editwarning1').style.display = 'none';
		}
	}
	else
	{
		_type = document.getElementById('htype').value;
		if(_type == '45')  
		{
			document.getElementById('char_other').style.display = 'block';
			document.getElementById('hothertype').style.display = 'block';
			document.getElementById('warning1').style.display = 'block';
		}
		else 
		{
			document.getElementById('hothertype').value='';
			document.getElementById('char_other').style.display = 'none';
			document.getElementById('hothertype').style.display = 'none';
			document.getElementById('warning1').style.display = 'none';
		}
	}
 }
////////////////// --------All Day ----------////////////////////////
function wholeday(cbid) 
{
	if(cbid=='AllDay')
	{
		if(document.getElementById('AllDay').checked==true)
		{
			document.getElementById('edate').value='';
			document.getElementById('etimetd').style.display = 'none';
			document.getElementById('AllDay').value = 'ON';
			document.getElementById('edate').value=document.getElementById('sdate').value;
			document.getElementById('etime').value='23:30';
		}
		else if(document.getElementById('AllDay').checked== false) 
		{
			document.getElementById('etimetd').style.display = 'block';
			document.getElementById('AllDay').value = 'OFF';
		}
	}
	else 
	{
		if(document.getElementById('editAllDay').checked==true)
		{
			document.getElementById('editedate').value='';
			document.getElementById('editetimetd').style.display = 'none';
			document.getElementById('editAllDay').value = 'ON';
			document.getElementById('editedate').value=document.getElementById('editsdate').value;
			document.getElementById('editetime').value='23:30';
		}
		else if(document.getElementById('editAllDay').checked== false) 
		{
			document.getElementById('editetimetd').style.display = 'block';
			document.getElementById('editAllDay').value = 'OFF';
		}
	}
}
////////////////// -------- Show Map ----------////////////////////////
function initialize(mapcontext,address) 
{
	var add,add1,add2;
	if(mapcontext=='create' || mapcontext=='edit')
	{
		if(param=='edit') 
		{
			add=document.getElementById('editvcity').value;
			add1=document.getElementById('editvstreet').value;
			add2=document.getElementById('editvaddress1').value;
			
			if(add == '')
			{
				alert(displayMsg("Enter City"));
				document.getElementById('editvcity').focus();
				return false;
			}
			else
			{	
				document.getElementById('editmapwindow').style.display = 'block';
			}
			
		}
		else
		{
			add=document.getElementById('vcity').value;
			add1=document.getElementById('vstreet').value;
			add2=document.getElementById('vaddress1').value;

			if(add == '')
			{
				alert(displayMsg("Enter City"));
				document.getElementById('vcity').focus();
				return false;
			}
			else
			{	
				document.getElementById('mapwindow').style.display = 'block';
			}
		}
		if(add1!="")
		{
			if(add2!='')
			{
				add=add2+','+add1 +','+ add;	
			}
			else
			{
				add = add1 +','+ add;
			}
		}
		else
		{
			if(add2!='')
			{
				add=add2+','+add;	
			}
			else
			{
				add = add;
			}
		}
		if (GBrowserIsCompatible()) 
		{
			if(param=='edit') 
			{
				map = new GMap2(document.getElementById("mapedit_canvas"));
			}
			else 
			{
				map = new GMap2(document.getElementById("map_canvas"));
			}
			/*if(ownercountry[0].fields_.longitude!='' && ownercountry[0].fields_.latitude!='')
			{
				map.setCenter(new GLatLng(ownercountry[0].fields_.latitude,ownercountry[0].fields_.longitude), 13);				
			}
			else
			{*/
				map.setCenter(new GLatLng(37.4419, -122.1419), 13);
			//}
			geocoder = new GClientGeocoder();
			map.addControl(new GLargeMapControl());
			//map.addControl(new google.maps.LocalSearch()); 
			showLocation(add);
		 }
	}
	else if(mapcontext=='view')
	{
		document.getElementById('viewmapwindow').style.display = 'block';
		document.getElementById('show_viewmap').style.display = 'none';
	 	if (GBrowserIsCompatible()) 
		{
			map = new GMap2(document.getElementById("viewmap_canvas"));
			/*if(ownercountry[0].fields_.longitude!='' && ownercountry[0].fields_.latitude!='')
			{
				map.setCenter(new GLatLng(ownercountry[0].fields_.latitude,ownercountry[0].fields_.longitude), 13);				
			}
			else
			{*/
				map.setCenter(new GLatLng(37.4419, -122.1419), 13);
			//}
			geocoder = new GClientGeocoder();
			map.addControl(new GLargeMapControl());
			showLocation(address);
      	}
	}
}

function showLocation(add) 
{
  var address = add;
  geocoder.getLocations(address, addAddressToMap);
}

function addAddressToMap(response)
{
  map.clearOverlays();
  if (!response || response.Status.code != 200) 
  {
		/*var d_loc='';
		if(ownercountry[0].fields_.locality!='')
		{
			d_loc+=ownercountry[0].fields_.locality;
			if(ownercountry[0].fields_.region!='')
			{
				d_loc+=','+ownercountry[0].fields_.region;
				if(ownercountry[0].fields_.country!='')
				{
					d_loc+=','+ownercountry[0].fields_.country;	
				}
			}
			else if(ownercountry[0].fields_.country!='')
			{
				d_loc+=','+ownercountry[0].fields_.country;	
			}
		}
		else if(ownercountry[0].fields_.region!='')
		{
			d_loc+=','+ownercountry[0].fields_.region;
			if(ownercountry[0].fields_.country!='')
			{
				d_loc+=','+ownercountry[0].fields_.country;	
			}
		}
		else if(ownercountry[0].fields_.country!='')
		{
			d_loc+=','+ownercountry[0].fields_.country;	
		}*/
		alert(displayMsg("mapaddress"));
		//showLocation(d_loc);
	} 
	else 
	{
		place = response.Placemark[0];
		point = new GLatLng(place.Point.coordinates[1],
							place.Point.coordinates[0]);
		//marker = new GMarker(point);
		marker = new GMarker(point, {draggable: true});
		GEvent.addListener(marker, "dragstart", function() {
			map.closeInfoWindow();
			});
		
		GEvent.addListener(marker, "dragend", function() {
			marker.openInfoWindowHtml();
			});
		map.addOverlay(marker);
		marker.openInfoWindowHtml(place.address + '<br>' +
		  '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
	}
}

function closemap(con)
{
	if(con=='create')
	{
		document.getElementById('mapwindow').style.display = 'none';
	}
	else if(con=='view')
	{
		document.getElementById('viewmapwindow').style.display = 'none';
		document.getElementById('show_viewmap').style.display = 'block';
	}
	else if(con=='edit')
	{
		document.getElementById('editmapwindow').style.display = 'none';			
	}
	else
	{
		
	}
}
////////////////// --------Hangout Other Type character count ----------////////////////////////
function char_htype() 
{
 	var current;
	var result1;
	if(param=='edit')
	{
		current=document.getElementById('edithothertype').value.length;
		result1='edithtypechars';
	}
	else
	{
		current=document.getElementById('hothertype').value.length;
		result1='htypechars';
	}
	var chars_left = 25 - current;
	if(param=='edit')
	{
		if(chars_left < 0)
		{
		   over = true;
		   document.getElementById('editwarning1').value ='Please remove extra characters! Limit is up to 25!';
		}
		else
		{
			over = false;
			document.getElementById('editwarning1').value='';
		}
		
	}
	else
	{
		if(chars_left < 0)
		{
		   over = true;
		   document.getElementById('warning1').value ='Please remove extra characters! Limit is up to 25!';
		}
		else
		{
			over = false;
			document.getElementById('warning1').value='';
		}
	}
	document.getElementById(result1).innerHTML = chars_left;
}
 ////////////////// --------Guest Message Character Count----------////////////////////////
var maxwords = 500;
function charsLeft()
{
	var message;
	var result;
	if(param == 'edit')
	{
		message = document.getElementById('editmessage');
		result='editleftchar';
	}
	else if(param=='invite')
	{
		message = document.getElementById('invitefriendsmsg');
		result='ifsleftchar';
	}
	else if(param=='morefriends')
	{
		message = document.getElementById('invitemoremsg');
		result='imfleftchar';
	}
	else
	{
		message = document.getElementById('message');
		result='leftchar';
	}
	if(message.value!='')
	{
		var len = message.value.length;
	}
	else
	{
		var len=0;	
	}
	
	if (len > maxwords) {
	message.value = message.value.substr(0,maxwords);
	len = maxwords;
	}
	if(document.getElementById(result))
	document.getElementById(result).innerHTML = maxwords - len;
}

function viewdetails(hid,checkPast,actType)
{
	post_params();
	var url = appServletURL+'/GetJSONHangoutDetails?'+ urlParams.join('');
	postdata = {hid:hid};
	params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
	var refreshInterval=0;
	var ts = new Date().getTime();
	var sep = "?";
	if (refreshInterval && refreshInterval > 0) 
	{
	   ts = Math.floor(ts / (refreshInterval * 1000));
	}
	if (url.indexOf("?") > -1) 
	{
	   sep = "&";
	}
	url = [ url, sep, "nocache=", ts ].join("");
	param = 'view';
	function view_callback(response) 
	{        
		if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
		{
			err_conunt++;
			if(err_conunt>4)
			{
				var message = Customized_ErrorMessages('servlet');
				 alert(message);
				 err_conunt=0;
				 showPages('hangout');
				 return;
			}
			else
			{
				viewdetails(hid,checkPast,actType);
			}
		}
		else
		{
			jsonvar = eval('('+response.text+')'); 
			document.getElementById('await_list').style.display='none';
			document.getElementById('wait').style.display='none';
			document.getElementById('acc_list').style.display='none';
			document.getElementById('accept_div').style.display='none';
			document.getElementById('maybe_list').style.display='none';
			document.getElementById('maybe_div').style.display='none';
			document.getElementById('reject_list').style.display='none';
			document.getElementById('reject_div').style.display='none';
			
			var hangout_accept_data1 = new Array();	
			var hangout_accept_data = new Array();	
			document.getElementById('viewHangout').style.display='block';
			document.getElementById('loading').style.display='none';	
			u++;
			var rem;
			owner_status(hid,checkPast);
			
			if(jsonvar.TypeID>=1 && jsonvar.TypeID<=46)
			{
					document.getElementById('hangout_TypeName').innerHTML=displayMsg(jsonvar.TypeName);						
			}
			else
			{
				document.getElementById('hangout_TypeName').innerHTML=displayMsg("Other")+' - '+jsonvar.TypeName;
			}
			var hostdet=new Array();
			hostdet=GetFriendDataById(jsonvar.HostID[0].osid);
			
			if(hostdet!=0)
			{
				document.getElementById('hostimage').innerHTML='<img src='+hostdet[1]+' border="0" class="photoborder">';
				document.getElementById('hostname').innerHTML='('+displayMsg('Invited by')+': '+hostdet[0]+')';	
			}
			else
			{
				if(jsonvar.HostID[0].name!='' && typeof(jsonvar.HostID[0].name)!='undefined')
				{
					document.getElementById('hostimage').innerHTML='<img src='+jsonvar.HostID[0].imageURL+' border="0" class="photoborder">';
					document.getElementById('hostname').innerHTML='('+displayMsg('Invited by')+': '+jsonvar.HostID[0].name+')';	
				}
				else
				{
					document.getElementById('hostimage').innerHTML='<img src="'+appPageURL+'/images/nophoto.gif" border="0" class="photoborder">';
					document.getElementById('hostname').innerHTML='('+displayMsg('Invited by')+': '+displayMsg('hostFriend')+')';	
				}
			}
			
			document.getElementById('invitedfrds').innerHTML="<a href='javascript:void(0);' onclick='seeallinvites();' >"+jsonvar.invitedPersons.length+" "+displayMsg('Friends')+"</a>";		
			document.getElementById('vhtitle').innerHTML=jsonvar.Title;
			if(jsonvar.address2!='')
			{
				if(jsonvar.address1!='')
				{
					showmap(jsonvar.address1+','+jsonvar.address2+','+jsonvar.city);
				}
				else
				{
					showmap(jsonvar.address2+','+jsonvar.city);
				}
			}
			else
			{
				if(jsonvar.address1!='')
				{
					showmap(jsonvar.address1+','+jsonvar.city);
				}
				else
				{
					showmap(jsonvar.city);
				}
			}
		
			document.getElementById('time').innerHTML='<td width="85%">'+jsonvar.StartTime+'  '+displayMsg("To")+' '+jsonvar.EndTime+' </td>';
			var view_address ='<td>';
			view_address = jsonvar.address1;
			if(trimAll(jsonvar.address2) != 0)
			{
				view_address += ',<br>'+jsonvar.address2;
			}
			view_address += ',<br>'+jsonvar.city+'</td>';
			document.getElementById('address').innerHTML=view_address;
			
			var desc="";
			var l_min=0;
			if(jsonvar.Description.length>50)
			{
				for(var l_max=50;l_max<=jsonvar.Description.length;l_max=l_max+50)
				{
					desc+=jsonvar.Description.substring(l_min,l_max);
					desc+='<br>';
					l_min=l_max;
					if((jsonvar.Description.length-l_max)<50)
					{
						l_max=jsonvar.Description.length;
						desc+=jsonvar.Description.substring(l_min,l_max);
						desc+='<br>';
					}
				}
			}
			else
			{
				desc=jsonvar.Description;
			}
			
			document.getElementById('desc').innerHTML='<td>'+desc+'</td>';
			if(actType==1 || actType==3 || actType==4)
			{
				document.getElementById('hangout_media').style.display='none';
			}
			else
			{
				media_links();	
			}
			if(await_arr.length!=0)
			{
				clearArray(await_arr);
			}
			if(canceluids.length!=0)
			{
				clearArray(canceluids);
			}
			await_arr.length=0;
			canceluids.length=0;
			var iuids= new Array();
			for(var i=0; jsonvar.invitedPersons.length > i; i++)
			{
				await_arr[i]=jsonvar.invitedPersons[i];
				if(hostid==jsonvar.HostID[0].osid && checkPast!='past')
				{
					canceluids[i]=jsonvar.invitedPersons[i].osid;
					iuids[i]=jsonvar.invitedPersons[i].osid;
				}
			}
			awaiting_list(jsonvar.acceptedPersons,jsonvar.MayBePersons,jsonvar.RejectedPersons);
			responses_list(displayMsg('Accepted'),jsonvar.acceptedPersons,'acc_list','acc_content','seeless');
			responses_list(displayMsg('May be'),jsonvar.MayBePersons,'maybe_list','maybe_content','seeless');
			responses_list(displayMsg('Rejected'),jsonvar.RejectedPersons,'reject_list','reject_content','seeless');
			if(checkPast == 'past')
			{
				document.getElementById('view_past').innerHTML = "<a href='javascript:void(0);' onclick=getHtmlPage('past','','')><img src='"+appPageURL+"/images/back_arrow.gif' border=0 />&nbsp;"+displayMsg('btph')+"</a>";
			}
			else
			{
				document.getElementById('view_past').innerHTML = "<a href='javascript:void(0);' onclick=getHtmlPage('hangout','','')><img src='"+appPageURL+"/images/back_arrow.gif' border=0 />&nbsp;"+displayMsg('bth')+"</a>";
			}
			if(hostid==jsonvar.HostID[0].osid && checkPast!='past')
			{
				var auids=new Array();
				for(var i=0; jsonvar.acceptedPersons.length > i; i++)
				{
					auids[i]=jsonvar.acceptedPersons[i];
				}
				document.getElementById('ehangoutbtn').innerHTML = "<img src='"+appPageURL+"/images/edit_icon.gif'> <a href='javascript:void(0);' onClick=getHtmlPage('edit','"+hid+"','')> "+displayMsg('Edit')+" </a><img src='"+appPageURL+"/images/cancel.gif'><a href='javascript:void(0);' onClick=\"UpdateStatus(event,'cancel','"+hid+"','"+iuids+"','"+auids+"','"+escape(jsonvar.Title)+"')\"> "+displayMsg('Cancel')+" </a>";
			}
			else
			{
				document.getElementById('ehangoutbtn').innerHTML = "";
			}	
		}
		document.getElementById('loading').style.display='none';
		document.getElementById('viewHangout').style.display='block';
	}
	gadgets.io.makeRequest(url,view_callback ,params);
}

function awaiting_list(acc_arr,may_arr,rej_arr)
{
	var tot_arr=new Array();
	tot_arr=acc_arr.concat(may_arr,rej_arr);
	for(var j=0;j<tot_arr.length;j++)
	{
		for(var i=0;i<await_arr.length;i++)
		{
			if(await_arr[i].osid==tot_arr[j].osid)
			{
				await_arr.splice(i,1);
			}
		}
	}
	
	responses_list(displayMsg('Awaiting response'),await_arr,'await_list','await_content','seeless');
}

function responses_list(context,id_arr,div_name,div_content,see_count)
{
	var more="";
	var response_data=new Array();
	var content="<table border='0' width='100%' >";
	var rowcount=0;
	var i=0;
	if(document.getElementById(div_name))
	document.getElementById(div_name).innerHTML="";
	//total=jsonvar.invitedPersons.length-(jsonvar.acceptedPersons.length+jsonvar.RejectedPersons.length+jsonvar.MayBePersons.length);
	var cnt_str="";
	if(	jsonvar.acceptedPersons.length!=0)
	{
		cnt_str+=jsonvar.acceptedPersons.length+' '+displayMsg('Yes')+' , ';
	}
	else
	{
		cnt_str+='0 '+displayMsg('Yes')+' , ';
	}
	if(jsonvar.MayBePersons.length!=0)
	{
		cnt_str+=jsonvar.MayBePersons.length+' '+displayMsg('May be')+' , ';
	}
	else
	{
		cnt_str+='0 '+displayMsg('May be')+' , ';
	}
	if(jsonvar.RejectedPersons.length!=0)
	{
		cnt_str+=jsonvar.RejectedPersons.length+' '+displayMsg('No')+' , ';
	}
	else
	{
		cnt_str+='0 '+displayMsg('No')+' , ';
	}
	cnt_str+= await_arr.length+' '+displayMsg('Awaiting response')+'.';
	document.getElementById('stat').innerHTML= cnt_str;
	if(id_arr.length!=0)
	{
		while(i<id_arr.length)
		{
			
			if(see_count=='seeless')
			{
				rowcount++;
				if(rowcount<3)
				{
					content+="<tr >";
					for(var j=0;j<2;j++)
					{
						if(i<id_arr.length)
						{
							response_data=GetFriendDataById(id_arr[i].osid);
							if(response_data!=0)
							{
								content+="<td width=50% align='center' ><table border='0'><tr><td align='center'><img src='" + response_data[1] + "' class='photoborder' /></td></tr><tr><td align='center' style='font-size:9px'>"+unescape(response_data[0]).toLowerCase().substring(0,14)+"...</td></tr></table></td>";
							}
							else
							{
								if(id_arr[i].name!='' && typeof(id_arr[i].name)!='undefined')
								{
									content+="<td width=50% align='center' ><table border='0'><tr><td align='center'><img src='" + id_arr[i].imageURL + "' class='photoborder' /></td></tr><tr><td align='center' style='font-size:9px'>"+unescape(id_arr[i].name).toLowerCase().substring(0,14)+"...</td></tr></table></td>";
								}
								else
								{
									content+="<td width=50% align='center' ><table border='0'><tr><td align='center'><img src='"+appPageURL+"/images/nophoto.gif' class='photoborder'/></td></tr><tr><td align='center' style='font-size:9px'>"+displayMsg('hostFriend')+"</td></tr></table></td>";
								}
							}
							i++;
						}
					}
					content+="</tr>";
				}
				else
				{
					break;
				}
			}
			else if(see_count=='seemore')
			{
				content+="<tr >";
				for(var j=0;j<2;j++)
				{
					if(i<id_arr.length)
					{
						response_data=GetFriendDataById(id_arr[i].osid);
						if(response_data!=0)
						{
							content+="<td width=50% align='center' ><table border='0'><tr><td align='center'><img src='" + response_data[1] + "' class='photoborder' /></td></tr><tr><td align='center' style='font-size:9px'>"+unescape(response_data[0]).toLowerCase().substring(0,14)+"...</td></tr></table></td>";
						}
						else
						{
							if(id_arr[i].name!='' && typeof(id_arr[i].name)!='undefined')
							{
								content+="<td width=50% align='center' ><table border='0'><tr><td align='center'><img src='" + id_arr[i].imageURL + "' class='photoborder' /></td></tr><tr><td align='center' style='font-size:9px'>"+unescape(id_arr[i].name).toLowerCase().substring(0,14)+"...</td></tr></table></td>";
							}
							else
							{
								content+="<td width=50% align='center' ><table border='0'><tr><td align='center'><img src='"+appPageURL+"/images/nophoto.gif' class='photoborder'/></td></tr><tr><td align='center' style='font-size:9px'>"+displayMsg('hostFriend')+"</td></tr></table></td>";
							}
						}
						i++;
					}
				}
				content+="</tr>";
			}
		}
		if(id_arr.length > 4 && see_count=='seeless')
		{
			more="<a href='javascript:void(0);' onclick=\"see_more('"+context+"')\">"+displayMsg('See More')+"</a>";
		}
		else if(see_count=='seemore')
		{
			more="<a href='javascript:void(0);' onclick=\"see_less('"+context+"')\">"+displayMsg('See Less')+"</a>";
		}
		main_tbl='<table border="0"  cellspacing="0" width="100%" cellpadding="0" ><tr><td><b style="padding-left:5px; color:#002569"> '+context+' ('+id_arr.length+')</b></td><td style="padding-right:5px" align="right">'+more+'</td></tr></table>';
		document.getElementById(div_name).innerHTML=main_tbl;
		document.getElementById(div_content).innerHTML=content+'</table>';
	}
	if(await_arr.length==0 )
	{
		document.getElementById('await_list').style.display='none';
		document.getElementById('await_content').style.display='none';
		document.getElementById('wait').style.display='none';
		document.getElementById('wait_con').style.display='none';
	}
	else
	{
		document.getElementById('await_list').style.display='block';
		document.getElementById('await_content').style.display='block';
		document.getElementById('wait').style.display='block';
		document.getElementById('wait_con').style.display='block';
	}
	if(jsonvar.acceptedPersons.length==0)
	{
		document.getElementById('acc_list').style.display='none';
		document.getElementById('acc_content').style.display='none';
		document.getElementById('accept_div').style.display='none';
		document.getElementById('acc_con').style.display='none';
	}
	else
	{
		document.getElementById('acc_list').style.display='block';
		document.getElementById('acc_content').style.display='block';
		document.getElementById('accept_div').style.display='block';
		document.getElementById('acc_con').style.display='block';
	}
	if(jsonvar.MayBePersons.length==0)
	{
		document.getElementById('maybe_list').style.display='none';
		document.getElementById('maybe_content').style.display='none';
		document.getElementById('maybe_div').style.display='none';
		document.getElementById('maybe_con').style.display='none';
	}
	else
	{
		document.getElementById('maybe_list').style.display='block';
		document.getElementById('maybe_content').style.display='block';
		document.getElementById('maybe_div').style.display='block';
		document.getElementById('maybe_con').style.display='block';
	}
	if(jsonvar.RejectedPersons.length==0)
	{
		document.getElementById('reject_list').style.display='none';
		document.getElementById('reject_content').style.display='none';
		document.getElementById('reject_div').style.display='none';
		document.getElementById('reject_con').style.display='none';
	}
	else
	{
		document.getElementById('reject_list').style.display='block';
		document.getElementById('reject_content').style.display='block';
		document.getElementById('reject_div').style.display='block';
		document.getElementById('reject_con').style.display='block';
	}
	
	if(jsonvar.RejectedPersons.length==0 && jsonvar.MayBePersons.length==0 && jsonvar.acceptedPersons.length==0 && await_arr.length==0)
	{
		document.getElementById('bot_tr').style.display='none';
	}
	else
	{
		document.getElementById('bot_tr').style.display='block';
	}
	content="";
	main_tbl="";
	more="";
	adjustPageHeight();
}

function see_more(con)
{
	if(con==displayMsg('Awaiting response'))
	{
		responses_list(displayMsg('Awaiting response'),await_arr,'await_list','await_content','seemore')
	}
	else if(con==displayMsg('Accepted'))
	{
		responses_list(displayMsg('Accepted'),jsonvar.acceptedPersons,'acc_list','acc_content','seemore');
	}
	else if(con==displayMsg('May be'))
	{
		responses_list(displayMsg('May be'),jsonvar.MayBePersons,'maybe_list','maybe_content','seemore');
	}
	else if(con==displayMsg('Rejected'))
	{
		responses_list(displayMsg('Rejected'),jsonvar.RejectedPersons,'reject_list','reject_content','seemore');
	}
}

function see_less(con)
{
	if(con==displayMsg('Awaiting response'))
	{
		responses_list(displayMsg('Awaiting response'),await_arr,'await_list','await_content','seeless')
	}
	else if(con==displayMsg('Accepted'))
	{
		responses_list(displayMsg('Accepted'),jsonvar.acceptedPersons,'acc_list','acc_content','seeless');
	}
	else if(con==displayMsg('May be'))
	{
		responses_list(displayMsg('May be'),jsonvar.MayBePersons,'maybe_list','maybe_content','seeless');
	}
	else if(con==displayMsg('Rejected'))
	{
		responses_list(displayMsg('Rejected'),jsonvar.RejectedPersons,'reject_list','reject_content','seeless');
	}
}

var photo_all;
var video_all;
var edit_links;
function media_links()
{
	var photo_data="<table width='100%'><tr><td align='left'>";	
	photo_all="<table>";
	edit_links="<table cellpadding='0' cellspacing='0' width='98%' border='0' align='center'>";
	if(jsonvar.PhotoLinks.length!=0)
	{
		
		document.getElementById('media_editLinks').style.display='block';
		edit_links+='<tr><td colspan="4" style="height:10"></td></tr><tr><td colspan="4" style="font-weight:bold; color:#00367b">Photo Links</td></tr><tr><td colspan="4" style="height:10"></td></tr><tr><td width="150" class="showpast">Title</td><td width="225" class="showpast">Urls</td><td width="150" class="showpast">&nbsp;</td><td width="150" class="showpast">&nbsp;</td></tr><tr><td height="3" colspan="4"></td></tr>';
		var k=0;
		var count=0;			
		for (var i=0;i<jsonvar.PhotoLinks.length;i++)
		{
			if(i<=1)
			{
				if(count < 2)
				{	
					photo_data+="<a href='"+jsonvar.PhotoLinks[i].url+"' target='_blank' title='"+decode_text(unescape(jsonvar.PhotoLinks[i].title))+"'>"+decode_text(unescape(jsonvar.PhotoLinks[i].title)).substring(0,20)+"</a>";
					if(count==0 && jsonvar.PhotoLinks.length > 1)
					{
						photo_data+="&nbsp;,&nbsp;";
					}
					else if(count==1 && jsonvar.PhotoLinks.length > 2)
					{
						photo_data+="&nbsp;,&nbsp;...</td><td align='right'><a href='javascript:void(0)' onclick=media_showlinks('photo')> "+displayMsg('See More')+" </a></td>";	
					}
					if(jsonvar.PhotoLinks.length < 3)
					{
						edit_links+="<tr class='altrow'><td width='20%' height='50px'><span id='sp_p_title_"+i+"'>"+decode_text(unescape(jsonvar.PhotoLinks[i].title)).substring(0,15)+"</span><input id='in_p_title_"+i+"' value='"+decode_text(unescape(jsonvar.PhotoLinks[i].title))+"' type='text' style='display:none' width='30px'/></td><td width='50%'><span id='sp_p_url_"+i+"'>"+jsonvar.PhotoLinks[i].url+"</span><input id='in_p_url_"+i+"' value='"+jsonvar.PhotoLinks[i].url+"'  type='text' style='display:none' width='100px' /></td><td width='10%'><a id='edit_p_btn_"+i+"' style='cursor:pointer' onclick=edit_link('"+i+"','p') >Edit</a></td><td width='10%'><a id='cancel_p_btn_"+i+"' disabled='true' onclick=cancel_edit_link('"+i+"','p') >Cancel</a></td></tr>";
					}
				}
			}
			else
			{
				for(var j=0;j<5;j++)
				{
					if(k<jsonvar.PhotoLinks.length)
					{
						if(jsonvar.PhotoLinks.length >1 && k!=jsonvar.PhotoLinks.length-1)
						{
							photo_all+="<td align='center'><table><tr><td><a href='"+jsonvar.PhotoLinks[k].url+"' target='_blank' title='"+decode_text(unescape(jsonvar.PhotoLinks[k].title))+"'>"+decode_text(unescape(jsonvar.PhotoLinks[k].title)).substring(0,15)+"</a>,</td></tr></table></td>";
							
							edit_links+="<tr><td width='20%'><span id='sp_p_title_"+k+"'>"+decode_text(unescape(jsonvar.PhotoLinks[k].title)).substring(0,15)+"</span><input id='in_p_title_"+k+"' value='"+decode_text(unescape(jsonvar.PhotoLinks[k].title))+"' type='text' style='display:none' width='30px'/></td><td width='50%' ><span id='sp_p_url_"+k+"'>"+jsonvar.PhotoLinks[k].url+"</span><input id='in_p_url_"+k+"' value='"+jsonvar.PhotoLinks[k].url+"' type='text' style='display:none' width='100px' /></td><td width='10%' ><a id='edit_p_btn_"+k+"' style='cursor:pointer' onclick=edit_link('"+k+"','p') >Edit</a></td><td width='10%'><a id='cancel_p_btn_"+k+"' disabled='true' onclick=cancel_edit_link('"+k+"','p') >Cancel</a></td></tr>";
						}
						else if(k==jsonvar.PhotoLinks.length-1)
						{
							photo_all+="<td align='center'><table><tr><td><a href='"+jsonvar.PhotoLinks[k].url+"' target='_blank' title='"+decode_text(unescape(jsonvar.PhotoLinks[k].title))+"'>"+decode_text(unescape(jsonvar.PhotoLinks[k].title)).substring(0,15)+"</a></td></tr></table></td>";
							
							edit_links+="<tr><td width='20%'><span id='sp_p_title_"+k+"'>"+decode_text(unescape(jsonvar.PhotoLinks[k].title)).substring(0,15)+"</span><input id='in_p_title_"+k+"' value='"+decode_text(unescape(jsonvar.PhotoLinks[k].title))+"' type='text' style='display:none' width='30px'/></td><td width='50%' ><span id='sp_p_url_"+k+"'>"+jsonvar.PhotoLinks[k].url+"</span><input id='in_p_url_"+k+"' value='"+jsonvar.PhotoLinks[k].url+"' type='text' style='display:none' width='100px' /></td><td width='10%' ><a id='edit_p_btn_"+k+"' style='cursor:pointer' onclick=edit_link('"+k+"','p') >Edit</a></td><td width='10%'><a id='cancel_p_btn_"+k+"' disabled='true' onclick=cancel_edit_link('"+k+"','p') >Cancel</a></td></tr>";
						}
						
					}
					k++;
				}
				photo_all+="</tr>";
			}
			count++;
		}
		photo_all+="</table>";
	}
	else
	{
		photo_data+="<a href='javascript:void(0)' onclick=topnav('photos')>"+displayMsg('apl')+"</a></td>";
	}
	photo_data+='</tr></table>';
	if(document.getElementById('photolinks'))
	document.getElementById('photolinks').innerHTML=photo_data;
	/////////////////video links///////////////////
	var video_data="<table width='100%'><tr><td align='left'>";	
	video_all="<table><tr>";
	
	if(jsonvar.VideoLinks.length!=0)
	{
		document.getElementById('media_editLinks').style.display='block';
		edit_links+='<tr><td colspan="4" style="height:10"></td></tr><tr><td colspan="4" style="font-weight:bold; color:#00367b">Video Links</td></tr><tr><td colspan="4" style="height:10"></td></tr><tr><td width="150" class="showpast">Title</td><td width="225" class="showpast">Urls</td><td width="150" class="showpast">&nbsp;</td><td width="150" class="showpast">&nbsp;</td></tr><tr><td height="3" colspan="4"></td></tr>';
		var count=0;
		var a=0;
		for (var i=0;i<jsonvar.VideoLinks.length;i++ )
		{
			if(i<=1)
			{
				if(count < 2)
				{			
					video_data+='<a href='+jsonvar.VideoLinks[i].url+' target="_blank" title="'+decode_text(unescape(jsonvar.VideoLinks[i].title))+'">'+decode_text(unescape(jsonvar.VideoLinks[i].title)).substring(0,20)+'</a>';
					if(count==0 && jsonvar.VideoLinks.length > 1)
					{
						video_data+="&nbsp;,&nbsp;";
					}
					else if(count==1 && jsonvar.VideoLinks.length > 2)
					{
						video_data+="&nbsp;,&nbsp;...</td><td align='right' ><a href='javascript:void(0)' onclick=media_showlinks('video')> "+displayMsg('See More')+" </a></td>";
					}
					if(jsonvar.VideoLinks.length < 3)
					{
						edit_links+="<tr><td width='20%'><span id='sp_v_title_"+i+"'>"+decode_text(unescape(jsonvar.VideoLinks[i].title)).substring(0,15)+"</span><input id='in_v_title_"+i+"' value='"+decode_text(unescape(jsonvar.VideoLinks[i].title))+"' type='text' style='display:none' width='30px' /></td><td width='50%'  ><span id='sp_v_url_"+i+"'>"+jsonvar.VideoLinks[i].url+"</span><input id='in_v_url_"+i+"' value='"+jsonvar.VideoLinks[i].url+"' type='text' style='display:none' width='100px'/></td><td width='10%'  ><a id='edit_v_btn_"+i+"' style='cursor:pointer' onclick=edit_link('"+i+"','v') >Edit</a></td><td width='10%'><a id='cancel_v_btn_"+i+"' disabled='true' onclick=cancel_edit_link('"+i+"','v') >Cancel</a></td></tr>";
					}
				}
			}
			else
			{
				for(var j=0;j<5;j++)
				{
					if(a <jsonvar.VideoLinks.length)
					{
						if(jsonvar.VideoLinks.length >1 && a!=jsonvar.VideoLinks.length-1)
						{
							video_all+="<td align='center'><table><tr><td><a href='"+jsonvar.VideoLinks[a].url+"' target='_blank' title='"+decode_text(unescape(jsonvar.VideoLinks[a].title))+"'>"+decode_text(unescape(jsonvar.VideoLinks[a].title)).substring(0,15)+"</a>,</td></tr></table></td>";
							
							edit_links+="<tr><td width='20%'><span id='sp_v_title_"+a+"'>"+decode_text(unescape(jsonvar.VideoLinks[a].title)).substring(0,15)+"</span><input id='in_v_title_"+a+"' value='"+decode_text(unescape(jsonvar.VideoLinks[a].title))+"' type='text' style='display:none' width='30px' /></td><td width='50%' ><span id='sp_v_url_"+a+"'>"+jsonvar.VideoLinks[a].url+"</span><input id='in_v_url_"+a+"' value='"+jsonvar.VideoLinks[a].url+"' type='text' style='display:none' width='100px' /></td><td width='10%'  ><a id='edit_v_btn_"+a+"' style='cursor:pointer' onclick=edit_link('"+a+"','v') >Edit</a></td><td width='10%'><a id='cancel_v_btn_"+a+"' disabled='true' onclick=cancel_edit_link('"+a+"','v') >Cancel</a></td></tr>";
						}
						else if(a==jsonvar.VideoLinks.length-1)
						{
							video_all+="<td align='center'><table><tr><td><a href='"+jsonvar.VideoLinks[a].url+"' target='_blank' title='"+decode_text(unescape(jsonvar.VideoLinks[a].title))+"'>"+decode_text(unescape(jsonvar.VideoLinks[a].title)).substring(0,15)+"</a></td></tr></table></td>";
							
							edit_links+="<tr><td width='20%'><span id='sp_v_title_"+a+"'>"+decode_text(unescape(jsonvar.VideoLinks[a].title)).substring(0,15)+"</span><input id='in_v_title_"+a+"' value='"+decode_text(unescape(jsonvar.VideoLinks[a].title))+"' type='text' style='display:none' width='30px' /></td><td width='50%' ><span id='sp_v_url_"+a+"'>"+jsonvar.VideoLinks[a].url+"</span><input style='display:none' id='in_v_url_"+a+"' value='"+jsonvar.VideoLinks[a].url+"' type='text' width='100px'  /></td><td width='10%' ><a id='edit_v_btn_"+a+"' style='cursor:pointer' onclick=edit_link('"+a+"','v') >Edit</a></td><td width='10%'><a id='cancel_v_btn_"+a+"' disabled='true' onclick=cancel_edit_link('"+a+"','v') >Cancel</a></td></tr>";
						}
					}
					a++;
				}
				video_all+="</tr>";
			}
			count++;
		}
		video_all+="</table>";
	}	
	else
	{
		video_data+="<a href='javascript:void(0)' onclick=topnav('videos')>"+displayMsg('avl')+"</a></td>";
	}
	video_data+='</tr></table>';
	edit_links+="<tr><td colspan='4' valign='middle' align='right'></td></tr><tr><td colspan='4' valign='middle' align='right'><input id='update_links' value='Update Links' class='smallbutton' onclick='update_links()' type='button' disabled='true' style='cursor:pointer'/></td></tr></table>";
	if(document.getElementById('videolinks'))
	document.getElementById('videolinks').innerHTML=video_data;
	document.getElementById('showMedia_div').style.display='none';
	document.getElementById('sample').style.display='none';
}
var media_url=new Array();
var media_title="";
function radiobtn_change(obj)
{
	media=obj;
	if(media=='photos')
	{
		if(document.getElementById('sample_text'))
		document.getElementById('sample_text').innerHTML='<font style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#999999">('+displayMsg("samplePurls")+': http://picasaweb.google.com/username/myalbum or http://www.flickr.com/photos/username)</font>';
	}
	else if(media=='videos')
	{
		if(document.getElementById('sample_text'))
		document.getElementById('sample_text').innerHTML='<font style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#999999">('+displayMsg("sampleVurls")+': http://www.youtube.com/watch?v=videoid or http://video.google.com/videoplay?docid=videoid)</font>';
	}
}
function media_add()
{
	var add_status=media_validations();
	var param_media="";
	if(add_status!=false)
	{
		if(document.getElementById('media_loader'))
		{
			document.getElementById('media_loader').style.display='block';	
		}

		//alert(jsonvar.PhotoLinks.length+"              "+jsonvar.VideoLinks.length);
		if(param=='view' && media_url!='' && media_title!='')
		{
			if(jsonvar.PhotoLinks.length==0 && jsonvar.VideoLinks.length==0)
			{
				var ph_media_str='';
				var vi_media_str='';
				for(var i=0;i<jsonvar.PhotoLinks.length;i++)
				{
					ph_media_str+=jsonvar.PhotoLinks[i].title+"$$$"+jsonvar.PhotoLinks[i].url+",";
				}
				for(var i=0;i<jsonvar.VideoLinks.length;i++)
				{
					vi_media_str+=jsonvar.VideoLinks[i].title+"$$$"+jsonvar.VideoLinks[i].url+",";
				}
				if(media=='photos')
				{
					for(var i=0;i<media_url.length;i++)
					{
						ph_media_str+=media_title+"$$$"+media_url[i];
						if(i<(media_url.length-1))
						{
							ph_media_str+=',';	
						}
					}
					postdata = {hid : hid,uids : jsonvar.HostID[0].osid,action : 6,media : ph_media_str, hostid: hostid, appid:appId ,token:token};
				}
				else if(media=='videos')
				{
					for(var i=0;i<media_url.length;i++)
					{
						vi_media_str+=media_title+"$$$"+media_url[i];
						if(i<(media_url.length-1))
						{
							vi_media_str+=',';	
						}
					}
					postdata = {hid : hid,uids : jsonvar.HostID[0].osid,action :7,media : vi_media_str, hostid: hostid , appid:appId , token:token};
				}				
				var url=appServletURL+'/UpdateHangoutAction?'+ urlParams.join('');
				var params = {};
				params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
				params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
				params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
				params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;   
				document.getElementById('media_btn').disabled = true;
				if(media=="photos")
				{
					document.getElementById('m_id_vi').disabled=true;
				}
				else if(media=="videos")
				{
					document.getElementById('m_id_ph').disabled=true;
				}
				gadgets.io.makeRequest(url,
				function(response)
				{
					if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
					{
						err_conunt++;
						if(err_conunt>4)
						{
							var message = Customized_ErrorMessages('servlet');
							 alert(message);
							 err_conunt=0;
							document.getElementById('media_btn').disabled = false;
							document.getElementById('m_id_vi').disabled=false;
							document.getElementById('m_id_ph').disabled=false;
							document.getElementById('addMedia_div').style.display='none';	
							document.getElementById('sample').style.display='none';
							if(document.getElementById('media_loader'))
							{
								document.getElementById('media_loader').style.display='none';	
							}
							 return;
						}
						else
						{
							media_add();
						}
					}
					else
					{
						var html=eval('('+response.text+')');
						if(html.status==1)
						{
							if(document.getElementById('media_loader'))
							{
								document.getElementById('media_loader').style.display='none';	
							}
							document.getElementById('media_btn').disabled = false;
							document.getElementById('m_id_vi').disabled=false;
							document.getElementById('m_id_ph').disabled=false;
							document.getElementById('addMedia_div').style.display='none';	
							document.getElementById('sample').style.display='none';
							for(var i=0;i<media_url.length;i++)
							{
								var obj={"title":media_title,"url":media_url[i]};
								if(media=='photos')
								{
									jsonvar.PhotoLinks.push(obj);
								}
								else if(media=='videos')
								{
									jsonvar.VideoLinks.push(obj);
								}
							}
							media_links();
						}
					}
				},params );
			}
			else  if(media=='photos')
			{
				var media_str='';
				for(var i=0;i<jsonvar.PhotoLinks.length;i++)
				{
					media_str+=jsonvar.PhotoLinks[i].title+"$$$"+jsonvar.PhotoLinks[i].url+",";
				}
				for(var i=0;i<media_url.length;i++)
				{
					media_str+=media_title+"$$$"+media_url[i];
					if(i<(media_url.length-1))
					{
						media_str+=',';	
					}
				}
				postdata = {hid : hid,uids : jsonvar.HostID[0].osid,action : 6,media : media_str, hostid: hostid , appid:appId , token:token};
				var url=appServletURL+'/UpdateHangoutAction?'+ urlParams.join('');
				var params = {};
				params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
				params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
				params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
				params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;   
				document.getElementById('media_btn').disabled = true;
				document.getElementById('m_id_vi').disabled=true;
				gadgets.io.makeRequest(url,
				function(response)
				{
					if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
					{
						err_conunt++;
						if(err_conunt>4)
						{
							var message = Customized_ErrorMessages('servlet');
							 alert(message);
							 err_conunt=0;
							document.getElementById('media_btn').disabled = false;
							document.getElementById('m_id_vi').disabled=false;
							document.getElementById('m_id_ph').disabled=false;
							document.getElementById('addMedia_div').style.display='none';	
							document.getElementById('sample').style.display='none';
							if(document.getElementById('media_loader'))
							{
								document.getElementById('media_loader').style.display='none';	
							}
							return;
						}
						else
						{
							media_add();
						}
					}
					else
					{
						var html=eval('('+response.text+')');
						if(html.status==1)
						{
							if(document.getElementById('media_loader'))
							{
								document.getElementById('media_loader').style.display='none';	
							}
							document.getElementById('media_btn').disabled = false;
							document.getElementById('m_id_vi').disabled=false;
							document.getElementById('m_id_ph').disabled=false;
							document.getElementById('addMedia_div').style.display='none';	
							document.getElementById('sample').style.display='none';
							for(var i=0;i<media_url.length;i++)
							{
								var obj={"title":media_title,"url":media_url[i]};
								jsonvar.PhotoLinks.push(obj);
							}
							media_links();
						}
					}
				},params );
			}
			else if(media=='videos')
			{
				var media_str='';
				for(var i=0;i<jsonvar.VideoLinks.length;i++)
				{
					media_str+=jsonvar.VideoLinks[i].title+"$$$"+jsonvar.VideoLinks[i].url+",";
				}
				for(var i=0;i<media_url.length;i++)
				{
					media_str+=media_title+"$$$"+media_url[i];
					if(i<(media_url.length-1))
					{
						media_str+=',';	
					}
				}
				postdata = {hid : hid,uids : jsonvar.HostID[0].osid,action : 7,media : media_str, hostid: hostid , appid:appId , token:token};
				var url=appServletURL+'/UpdateHangoutAction?'+ urlParams.join('');
				var params = {};
				params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
				params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
				params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
				params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;   
				document.getElementById('media_btn').disabled = true;
				document.getElementById('m_id_ph').disabled=true;
				gadgets.io.makeRequest(url,
				function(response)
				{
					if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
					{
						err_conunt++;
						if(err_conunt>4)
						{
							var message = Customized_ErrorMessages('servlet');
							 alert(message);
							 err_conunt=0;
							document.getElementById('media_btn').disabled = false;
							document.getElementById('m_id_vi').disabled=false;
							document.getElementById('m_id_ph').disabled=false;
							document.getElementById('addMedia_div').style.display='none';	
							document.getElementById('sample').style.display='none';
							if(document.getElementById('media_loader'))
							{
								document.getElementById('media_loader').style.display='none';	
							}
							 return;
						}
						else
						{
							media_add();
						}
					}
					else
					{
						var html=eval('('+response.text+')');
						if(html.status==1)
						{
							if(document.getElementById('media_loader'))
							{
								document.getElementById('media_loader').style.display='none';	
							}
							document.getElementById('media_btn').disabled = false;
							document.getElementById('m_id_vi').disabled=false;
							document.getElementById('m_id_ph').disabled=false;
							document.getElementById('addMedia_div').style.display='none';	
							document.getElementById('sample').style.display='none';
							for(var i=0;i<media_url.length;i++)
							{
								var obj={"title":media_title,"url":media_url[i]};
								jsonvar.VideoLinks.push(obj);
							}
							media_links();
						}
					}
				},params );
			}
		}
		else
		{
			document.getElementById('addMedia_div').style.display='none';	
			document.getElementById('sample').style.display='none';
		}
	}
	else
	{
		if(document.getElementById('media_loader'))
		{
			document.getElementById('media_loader').style.display='none';	
		}	
	}
}

function media_validations(mailid)
{
	
	if(typeof(mailid)!='undefined' && mailid!='')
	{
		apos=mailid.indexOf("@");
		dotpos=mailid.lastIndexOf(".");	
		sub=dotpos-apos;
		len=mailid.length;
		if ( (apos<1) || (sub<2) || ((len-dotpos)<2) ) 
		{
			return false;
		}
		return true;
	}
	else
	{
		if(trimAll(document.getElementById('media_title').value)!=0 && trimAll(document.getElementById('media_url').value)!=0)
		{
			media_title=document.getElementById('media_title').value;
			media_title=encode_text(media_title);
			media_url=document.getElementById('media_url').value.split(',');
			var urlregex = new RegExp("^(http:\/\/){1}([0-9A-Za-z]+\.)");
			for(var i=0;i<media_url.length;i++)
			{
				if (media=='videos')
				{
					if(media_url[i]=='http://www.youtube.com/watch?v=videoid' || media_url[i]=='http://video.google.com/videoplay?docid=videoid' || media_url[i]=='http://' || media_url[i]=='http://')
					{
						alert(displayMsg('validVurl'));
						return false;
					}
					else
					{
						media_url[i]=encode_text(media_url[i]);
						
						if(urlregex.test(media_url[i]))
						{
							var result=url_valid(media_url[i],media);
							if(result!=false)
							{
								return true;
							}
							else
							{
								alert(displayMsg("validGorY"));
								document.getElementById('media_url').focus();
								return false;
							}
						}
						else
						{
						alert(displayMsg('validVurl'));
							document.getElementById('media_url').focus();
							return false;
						}
					}
				}
				else if(media=='photos')
				{
					if(media_url[i]=='http://' || media_url[i]=='http://')
					{
						alert(displayMsg("validPurl"));
						return false;
					}
					else
					{
						media_url[i]=encode_text(media_url[i]);
						
						if(urlregex.test(media_url[i]))
						{
							var result=url_valid(media_url[i],media);
							if(result!=false)
							{
								return true;
							}
							else
							{
								alert(displayMsg("validPurl"));
								document.getElementById('media_url').focus();
								return false;
							}
						}
						else
						{
							alert(displayMsg("validPurl"));
							document.getElementById('media_url').focus();
							return false;
						}
					}
				}
			}
			
		}
		else if(trimAll(document.getElementById('media_title').value)==0)
		{
			if(media=='videos')
			{
				alert(displayMsg("validVtitle"));
				document.getElementById('media_title').value ='';
				document.getElementById('media_title').focus();
				return false;
			}
			else if(media=='photos')
			{
				alert(displayMsg("validPtitle"));
				document.getElementById('media_title').value ='';
				document.getElementById('media_title').focus();
				return false;
			}
			
		}
		else if(trimAll(document.getElementById('media_url').value)==0)
		{
			if(media=='videos')
			{
				alert(displayMsg("validVurl"));
				document.getElementById('media_url').focus();
				return false;
			}
			else if(media=='photos')
			{
				alert(displayMsg("validPurl"));
				document.getElementById('media_url').focus();
				return false;
			}
			
		}
	}
}

function url_valid(val)
{
	var a="";
	if(media=='videos')
	{
		a=/(http:\/\/)?([a-zA-Z]+.)?youtube.com\/watch\?v=([\w-]+)/;
		var b=/(http:\/\/)?video.google.com\/videoplay\?docid=([\w-]+)/;
		if (val.length > 0)
		{
			val=val.replace(/(^\s*)/g," ");
			val=val.replace(/(\s*$)/g," ");
			var c=a.exec(val);
			var d=b.exec(val);
			
			if(d!=null || c!=null)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	}
	else if(media=='photos')
	{
		a=/(http:\/\/)?([a-zA-Z]+.)?([a-zA-Z]+.)?([a-zA-Z]+.)\//;
		if (val.length > 0)
		{
			val=val.replace(/(^\s*)/g," ");
			val=val.replace(/(\s*$)/g," ");
			var c=a.exec(val);
			if(c!=null)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	}
}

function media_showlinks(con)
{
	topnav('showMedia_div');
	
	if(con=="photo")
	{
		document.getElementById('media_header').innerHTML=displayMsg("yourPlinks");
		document.getElementById('media_show').innerHTML=photo_all;
	}
	else if(con=="video")
	{
		document.getElementById('media_header').innerHTML=displayMsg("yourVlinks");
		document.getElementById('media_show').innerHTML=video_all;
	}
	adjustPageHeight();
}

function media_editLinks(state)
{
	if(state=='open')
	{
		document.getElementById('sample').style.display='block';
		document.getElementById('showMedia_div').style.display='block';
		document.getElementById('media_header').innerHTML="Edit Photo/Video Links";
		document.getElementById('media_show').innerHTML=edit_links;
		adjustPageHeight();
	}
	else if(state=='close')
	{
		document.getElementById('showMedia_div').style.display='none';
		document.getElementById('sample').style.display='none';
		adjustPageHeight();
	}
}

function update_links()
{
	var urlregex = new RegExp("^(http:\/\/){1}([0-9A-Za-z]+\.)");
	if(jsonvar.PhotoLinks.length!=0)
	{
		var photos_str='';
		for (var i=0;i<jsonvar.PhotoLinks.length;i++ )
		{	
			if(document.getElementById('in_p_url_'+i).value!='' && document.getElementById('in_p_title_'+i).value!='')
			{
				var edit_title=encode_text(document.getElementById('in_p_title_'+i).value);
				if(document.getElementById('in_p_url_'+i).value=='http://')
				{
					alert(displayMsg("validPurl"));
					return;
				}
				else
				{
					var edit_url=encode_text(document.getElementById('in_p_url_'+i).value);
					if(urlregex.test(edit_url))
					{
						var result=url_valid(edit_url,'photos');
						if(result!=false)
						{
							photos_str+=edit_title+'$$$'+edit_url;
							if(i!=(jsonvar.PhotoLinks.length-1))
							{
								photos_str+=',';	
							}
						}
						else
						{
							alert(displayMsg("validPurl"));
							document.getElementById('in_p_url_'+i).focus();
							return;
						}
					}
					else
					{
						alert(displayMsg("validPurl"));
						document.getElementById('in_p_url_'+i).focus();
						return;
					}
				}
			}
			else
			{
				if(trimAll(document.getElementById('in_p_title_'+i).value)==0)
				{
					alert(displayMsg("validPtitle"));
					document.getElementById('in_p_title_'+i).focus();
					return;
				}
				else if(trimAll(document.getElementById('in_p_url_'+i).value)==0)
				{
					alert(displayMsg("validPurl"));
					document.getElementById('in_p_url_'+i).focus();
					return;
				}
			}
			
		}
		postdata = {hid : hid,uids : jsonvar.HostID[0].osid,action : 6,media : photos_str, hostid: hostid , appid:appId , token:token};
		var url=appServletURL+'/UpdateHangoutAction?'+ urlParams.join('');
		var params = {};
		params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
		params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
		params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
		params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;  
		gadgets.io.makeRequest(url,	
			function(response)
			{
				if(typeof(response.text) != 'undefined' || response.text!="" || response.errors[0]!="Error 500" || response.text != '{}' || response.text != null)
				{
					var html=eval('('+response.text+')');
					if(html.status==1)
					{
						if(jsonvar.PhotoLinks.length!=0)
						{
							clearArray(jsonvar.PhotoLinks);
						}
						var i=0;
						while(document.getElementById('in_p_title_'+i))
						{
							var obj={"title":document.getElementById('in_p_title_'+i).value,"url":document.getElementById('in_p_url_'+i).value};
							jsonvar.PhotoLinks.push(obj);
							i++;
						}
						
						if(jsonvar.VideoLinks.length==0 && jsonvar.PhotoLinks.length!=0)
						{
							media_links();
						}
					}
				}
				else
				{
					update_links();
					
				}
			},params );	
	}
	if(jsonvar.VideoLinks.length!=0)
	{
		var videos_str='';
		for (var i=0;i<jsonvar.VideoLinks.length;i++ )
		{	
			if(document.getElementById('in_v_url_'+i).value!='' && document.getElementById('in_v_title_'+i).value!='')
			{
				var edit_title=encode_text(document.getElementById('in_v_title_'+i).value);
				if(document.getElementById('in_v_url_'+i).value=='http://')
				{
					alert(displayMsg("validVurl"));
					return;
				}
				else
				{
					var edit_url=encode_text(document.getElementById('in_v_url_'+i).value);
					if(urlregex.test(edit_url))
					{
						var result=url_valid(edit_url,'videos');
						if(result!=false)
						{
							photos_str+=edit_title+'$$$'+edit_url;
							if(i!=(jsonvar.VideoLinks.length-1))
							{
								photos_str+=',';	
							}
						}
						else
						{
							alert(displayMsg("validVurl"));
							document.getElementById('in_v_url_'+i).focus();
							return;
						}
					}
					else
					{
						alert(displayMsg("validVurl"));
						document.getElementById('in_v_url_'+i).focus();
						return;
					}
				}
			}
			else
			{
				if(trimAll(document.getElementById('in_v_title_'+i).value)==0)
				{
					alert(displayMsg("validVtitle"));
					document.getElementById('in_v_title_'+i).focus();
					return;
				}
				else if(trimAll(document.getElementById('in_v_url_'+i).value)==0)
				{
					alert(displayMsg("validVurl"));
					document.getElementById('in_v_url_'+i).focus();
					return;
				}
			}
		}
		
		postdata = {hid : hid,uids : jsonvar.HostID[0].osid,action : 7,media : videos_str, hostid: hostid , appid:appId , token:token};
		var params = {};
		params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
		params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
		params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
		params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON; 
		var url=appServletURL+'/UpdateHangoutAction?'+ urlParams.join('');
		gadgets.io.makeRequest(url,	
			function(response)
			{
				if(typeof(response.text) != 'undefined' || response.text!="" || response.errors[0]!="Error 500" || response.text != '{}' || response.text != null)
				{
					var html=eval('('+response.text+')');
					if(html.status==1)
					{
						if(jsonvar.VideoLinks.length!=0)
						{
							clearArray(jsonvar.VideoLinks);
						}
						var j=0;
						while(document.getElementById('in_v_title_'+j))
						{
							var obj={"title":document.getElementById('in_v_title_'+j).value,"url":document.getElementById('in_v_url_'+j).value};
							jsonvar.VideoLinks.push(obj);
							j++;
						}
						
						media_editLinks('close')
						media_links();
					}
				}
				else
				{
					update_links();
					
				}
			},params );
	}		
	
}

function edit_link(id,con)
{
	//alert(id);
	if(con=='p')
	{
		document.getElementById("sp_p_title_"+id).style.display='none';
		document.getElementById("in_p_title_"+id).style.display='block';
		document.getElementById("sp_p_url_"+id).style.display='none';
		document.getElementById("in_p_url_"+id).style.display='block';	
		document.getElementById("edit_p_btn_"+id).disabled=true;
		document.getElementById("edit_p_btn_"+id).style.cursor='auto';
		document.getElementById("cancel_p_btn_"+id).disabled=false;
		document.getElementById("cancel_p_btn_"+id).style.cursor='pointer';
	}
	else if(con=='v')
	{
		document.getElementById("sp_v_title_"+id).style.display='none';
		document.getElementById("in_v_title_"+id).style.display='block';
		document.getElementById("sp_v_url_"+id).style.display='none';
		document.getElementById("in_v_url_"+id).style.display='block';	
		document.getElementById("edit_v_btn_"+id).disabled=true;
		document.getElementById("edit_v_btn_"+id).style.cursor='auto';
		document.getElementById("cancel_v_btn_"+id).disabled=false;
		document.getElementById("cancel_v_btn_"+id).style.cursor='pointer';
	}
	document.getElementById("update_links").disabled=false;
	/*document.getElementById(id).style.display='none';
	document.getElementById(id).style.display='block';	*/
}

function cancel_edit_link(id,con)
{
	if(con=='p')
	{
		document.getElementById("sp_p_title_"+id).style.display='block';
		document.getElementById("in_p_title_"+id).style.display='none';
		document.getElementById("in_p_title_"+id).value=document.getElementById("sp_p_title_"+id).innerHTML;
		document.getElementById("sp_p_url_"+id).style.display='block';
		document.getElementById("in_p_url_"+id).style.display='none';	
		document.getElementById("in_p_url_"+id).value=document.getElementById("sp_p_url_"+id).innerHTML;
		document.getElementById("edit_p_btn_"+id).disabled=false;
		document.getElementById("edit_p_btn_"+id).style.cursor='pointer';
		document.getElementById("cancel_p_btn_"+id).disabled=true;
		document.getElementById("cancel_p_btn_"+id).style.cursor='auto';
	}
	else if(con=='v')
	{
		document.getElementById("sp_v_title_"+id).style.display='block';
		document.getElementById("in_v_title_"+id).style.display='none';
		document.getElementById("in_v_title_"+id).value=document.getElementById("sp_v_title_"+id).innerHTML;
		document.getElementById("sp_v_url_"+id).style.display='block';
		document.getElementById("in_v_url_"+id).style.display='none';	
		document.getElementById("in_v_url_"+id).value=document.getElementById("sp_v_url_"+id).innerHTML;
		document.getElementById("edit_v_btn_"+id).disabled=false;
		document.getElementById("edit_v_btn_"+id).style.cursor='pointer';
		document.getElementById("cancel_v_btn_"+id).disabled=true;
		document.getElementById("cancel_v_btn_"+id).style.cursor='auto';
	}
	
	for(i=0;i<jsonvar.PhotoLinks.length;i++)
	{
		if(document.getElementById("in_p_title_"+i))
		{
			if(document.getElementById("in_p_title_"+i).style.display=='block')
			{
				document.getElementById("update_links").disabled=false;
				return;
			}
		}
	}
	
	for(i=0;i<jsonvar.VideoLinks.length;i++)
	{
		if(document.getElementById("in_v_title_"+i))
		{
			if(document.getElementById("in_v_title_"+i).style.display=='block')
			{
				document.getElementById("update_links").disabled=false;
				return;
			}
		}
	}
}

function seeallinvites()
{
	var invitename="<table>";
	if(jsonvar.invitedPersons.length!=0)
	{		
		for (var i=0;i<jsonvar.invitedPersons.length; )
		{ 	
			invitename+='<tr>';
			for (var j=0;j<7;j++)
			{				
				if(i<jsonvar.invitedPersons.length)
				{
					hangout_maybe_data=GetFriendDataById(jsonvar.invitedPersons[i].osid);					
					if(hangout_maybe_data!=0)
					{							
						invitename+='<td><table><tr><td align="center"><img src='+hangout_maybe_data[1]+' border="0" class="photoborder"></td></tr><tr><td align="center">'+hangout_maybe_data[0].replace("%20"," ").substring(0, 5) + '..</td></tr></table></td>';
						
					}
					else
					{
						if(jsonvar.invitedPersons[i].name!='' && typeof(jsonvar.invitedPersons[i].name)!='undefined')
						{
							invitename+='<td><table><tr><td align="center"><img src='+jsonvar.invitedPersons[i].imageURL+' border="0" class="photoborder"></td></tr><tr><td align="center">'+jsonvar.invitedPersons[i].name.replace("%20"," ").substring(0, 5) + '..</td></tr></table></td>';
						}
						else
						{
							invitename+='<td><table><tr><td align="center"><img src="'+appPageURL+'/images/nophoto.gif" border="0" class="photoborder"></td></tr><tr><td align="center">host\'s friend</td></tr></table></td>';	
						}
					}	
				}
				i++;
			}			
			invitename+='</tr>';
		}
		invitename+='</table>';
		document.getElementById('sample').style.display='block';
		document.getElementById('showallinvites').style.display='block';
		document.getElementById('showallinvites1').innerHTML=invitename;
	}
	
}

function GetFriendDataById(uid)
{  	
	var data = new Array();	
	if(puid_arr.length!=0)
	{			
		for (var i=0;i<puid_arr.length ;i++ )
		{		
		   	if (puid_arr[i]==uid)
			{
				if(uid==hostid)
				{
					data[0]=displayMsg("You");
				}
				else 
				{
					data[0]=pname_arr[i];
				}
				data[1]=thumb_arr[i];	
				data[2]=puid_url[i];
				return data;				
			}
		}
	}	
	return 0;
}
function owner_status(hid,checkPast)
{
	var num=isExistedacceptedUIDs(hostid);
	if(hostid!=jsonvar.HostID[0].osid)
	{
		if (num==0)
		{
			var data_yes ="";
			if(checkPast != 'past')
			{
				data_yes += "<b style='color:#002569'>RSVP: &nbsp;&nbsp;<a href='javascript:void(0);' onclick=show_responses('"+hid+"')><span id='aa'> "+displayMsg('Yes')+" </span>&nbsp;<img src='"+appPageURL+"/images/dropdown_icon.gif' border='0' /></a></b> ";
			}
			else
			{
				data_yes ="<b style='color:#002569'>RSVP: &nbsp;&nbsp;<span id='aa'> "+displayMsg('Yes')+" </span></b>&nbsp;&nbsp;&nbsp;";
			}
			document.getElementById('owner_status').innerHTML= data_yes;
		}
		else
		{
			var a=isExistedRejectedUIDs(hostid);
			if (a==0)
			{
				var data_no = "";
				if(checkPast != 'past')
				{
					data_no += "<b style='color:#002569'>RSVP: &nbsp;&nbsp;<a href='javascript:void(0);' onclick=show_responses('"+hid+"')><span id='aa'> "+displayMsg('No')+" </span>&nbsp;<img src='"+appPageURL+"/images/dropdown_icon.gif' border='0' /></a></b> ";
				}
				else
				{
					data_no = "<b style='color:#002569'>RSVP: &nbsp;&nbsp;<span id='aa'> "+displayMsg('No')+" </span></b>";
				}
				document.getElementById('owner_status').innerHTML= data_no;
			}
			else
			{
				var b=isExistedMayBeUIDs(hostid);
				if (b==0)
				{
					var data_maybe="";
					if(checkPast != 'past')
					{
						data_maybe += "<b style='color:#002569'>RSVP:&nbsp;&nbsp;<a href='javascript:void(0);' onclick=show_responses('"+hid+"')><span id='aa'> "+displayMsg('May be')+" </span>&nbsp;<img src='"+appPageURL+"/images/dropdown_icon.gif' border='0' /></a></b> ";
					}
					else
					{
						data_maybe="<b style='color:#002569'>RSVP: &nbsp;&nbsp;<span id='aa'> "+displayMsg('May be')+" </span></b>";
					}
					document.getElementById('owner_status').innerHTML = data_maybe;
				}
				else
				{
					var data_await = "";
					if(checkPast != 'past')
					{
						data_await += "<b style='color:#002569'>RSVP: &nbsp;&nbsp;<a href='javascript:void(0);' onclick=show_responses('"+hid+"')><span id='aa'>"+displayMsg('Awaiting response')+" </span>&nbsp;<img src='"+appPageURL+"/images/dropdown_icon.gif' border='0' /></a></b>";
					}
					else
					{
						data_await = "<b style='color:#002569'>RSVP: &nbsp;&nbsp;<span id='aa'>"+displayMsg('Awaiting response')+" </span></b>";	
					}
					document.getElementById('owner_status').innerHTML = data_await;
				}
			}
		}
	}
	else
	{
			document.getElementById('owner_status').innerHTML="<b style='color:#002569'>"+displayMsg('yis')+"</b>";
	}
}

function isHost(uids)
{		
	if(jsonvar.HostID[0].osid==uids)
	{
		return 0;
	}
	return 1;
}

function isExistedRejectedUIDs(uids)
{
	for (var j=0;j<jsonvar.RejectedPersons.length ; j++)
	{
		if(jsonvar.RejectedPersons[j].osid==uids)
		{
			return 0;
		}
	}
	return 1;
}
function isExistedMayBeUIDs(uids)
{
	for (var k=0;k<jsonvar.MayBePersons.length ; k++)
	{
		if(jsonvar.MayBePersons[k].osid==uids)
		{
			return 0;
		}
	}		
	return 1;
}

function isExistedacceptedUIDs(uids)
{	
	for (var l=0;l<jsonvar.acceptedPersons.length ; l++)
	{
		if(jsonvar.acceptedPersons[l].osid==uids)
		{
			return 0;
		}							
	}	
	return 1;
}
function clearArray(ary)
{	
	var len=ary.length;
	for (var j=0;j<len;j++ )
	{
		ary.splice(0,1);
	}	
}

function showmap(address1)
{
	if(address1=='') {
		document.getElementById('viewmapwindow').style.display = 'block';
		document.getElementById('show_viewmap').style.display = 'none';
	}
	else
	{
		initialize('view',address1);
	}

}
/*function getEditData() 
{
	param='edit';
	showPages('editHangout');
	document.getElementById('update').disabled=false;	
	document.getElementById('ld_edit').style.display='none';
	initialize('edit','noadd');
}*/

function get_noapp_friends()
{
	if(has_noapp_id.length!=0)
	{
		fsw('widget',5,6,escape('search friends'),'invitefriends');
	}
	else
	{
		document.getElementById('widget').innerHTML="All your ORKUT friends have installed the App.";
	}
}

function sendInvitation()
{
	if(document.getElementById('recipient_list').value!='')
	{
		var mail_ids='';
		for(var i=0;i<(document.getElementById('recipient_list').value.split(',')).length;i++)
		{
			var res=validate_email((document.getElementById('recipient_list').value.split(','))[i]);
			if(res==true)
			{
				mail_ids+=(document.getElementById('recipient_list').value.split(','))[i];
			}
			else
			{
				alert('Enter valid mail IDs.');
				return;
			}
			if(i!=(document.getElementById('recipient_list').value.split(',')).length-1)
			{
				mail_ids+='$$$';
			}
		}
		var url=appServletURL+'/InsertEmail?'+ urlParams.join('');
		postdata = {hostid : hostid,emailid:mail_ids,token:token};
		var params = {};
		params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
		params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
		params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
		params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;   
		gadgets.io.makeRequest(url,
		function(response)
		{
			if(typeof(response.text) != 'undefined' || response.text!="" || response.errors[0]!="Error 500" || response.text != '{}' || response.text != null)
			{
				var res=eval('('+response.text+')');
				
				if(res.Result==true)
				{
					document.getElementById('recipient_list').value='';
					alert("Invitations sent successfully");	
				}
				else if(res.Result==false)
				{
					alert("Problem sending Invitations.Check the e-mail ids.");	
				}
				
			}
			else
			{
				sendInvitation();
			}
		},params);
	}
	else 
	{
		requestSendMessage('','','');	
	}
}

function validate_email(email)
{
	if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}
function postActivity(feed,context,hid) 
{
	if(feed=="invitefriends")
	{
		var msg = document.getElementById('invitefriendsmsg').value;
		var table="<table><tr><td>"+msg+"</td></tr></table>";		
		var title='<a href="'+domainURL+'/AppInfo.aspx?appId='+appId+'" /> is inviting you to  <b>+<u>Add Hangout</u></b> </a>';
	}
	else if(feed=='invitemorefriends')
	{
	}
	else if(feed=='remindhangout')
	{
		var title="remindhangout";//title comes here 
		var msg=document.getElementById('message').value;
		var table="<table><tr><td>"+msg+"</td></tr></table>";
	}
	else if(feed=='cancelhangout')
	{
		var title="cancelled "+unescape(context);//title comes here 
		var msg=document.getElementById('message').value;
		var table="<table><tr><td><img src='"+appPageURL+"/images/logo50x50.gif'></td></tr></table>";
	}
	else if(feed=='createhangout')
	{
		var title=unescape(context);
		//var msg=document.getElementById('message').value;

		var table='<table width="480" style="border:0px solid #c0c0c0" cellspacing="0" cellpadding="0" align="center" background="'+appPageURL+'/images/act_stream.gif" height="60"><tr><td valign="top" colspan="2" style="height:5px"></td></tr><tr><td align="left" style="padding-left:5px" width="60" valign="middle"><a href="'+domainURL+'/Application.aspx?'+(unescape(puid_url[0]).split("?"))[1]+'&appId='+appId+'" target="_blank" style="text-decoration:none"><img src="'+appPageURL+'/images/logo50x50.gif" width="50" height="50" border="0" /></a></td><td width="55" align="center" valign="middle"><a href="'+domainURL+'/Application.aspx?'+(unescape(puid_url[0]).split("?"))[1]+'&appId='+appId+'" target="_blank" style="text-decoration:none"><img src="'+thumb_arr[0]+'" border="0" width="42" height="42" /></a></td><td width="390" align="left" style="font:11px verdana; padding-right:5px" valign="middle"><a href="'+domainURL+'/Application.aspx?'+(unescape(puid_url[0]).split("?"))[1]+'&appId='+appId+'" target="_blank" style="text-decoration:none">'+pname_arr[0]+' created a new Hangout - <b>'+unescape(context)+'</b></a></td></tr><tr><td valign="top" colspan="2" style="height:5px"></td></tr></table>';
	}
	else if(feed=='updatehangout')
	{
		var title="has updated <a href='javascript:void(0);' onclick=viewdetails("+hid+",'','')>"+unescape(context)+"</a>";//title comes here 
		var msg=document.getElementById('message').value;
		var table="<table><tr><td><img src='"+appPageURL+"/images/logo50x50.gif'></td></tr></table>";
	}
	else
	{		//not created 
	}
	var data = {};
	data[opensocial.Activity.Field.TITLE] = title;
	data[opensocial.Activity.Field.BODY] = table;
	var activity = opensocial.newActivity(data);
	opensocial.requestCreateActivity(activity, opensocial.CreateActivityPriority.HIGH, callback
	);
 } 

function callback()
{
	/*do nothing*/
}

function requestSendMessage(name,id,thumb)
{
	var msg_sent_flag=0;
	if(id!='')
	{
		var params = {};
		params[opensocial.Message.Field.TITLE]="Hangout Invitation";
		var body='Add the App here :'+domainURL+'/AppInfo.aspx?appId='+appId;
		var message = opensocial.newMessage(body, params);
		var recipient = id;
		opensocial.requestSendMessage(recipient, message, 
			function(response)
			{
				if(response.errorCode_==null)
				{
					for(var r=0;r<response.data_.recipientIds.length;r++)
					{
						FriendsSlider(0,'invitefriends',response.data_.recipientIds[r]);		
						var url=appServletURL+'/SetMailOrkut?'+ urlParams.join('');
						//post_params();
						postdata = { toosid : response.data_.recipientIds[r] , byosid : hostid , action:'insert' };
						var params = {};
						params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
						params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
						params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
						params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;   
						gadgets.io.makeRequest(url,
						function(response)
						{
							if(typeof(response.text) != 'undefined' || response.text!="" || response.errors[0]!="Error 500" || response.text != '{}' || response.text != null)
							{
								var res=eval('('+response.text+')');
								if(res.Result!=true)
									requestSendMessage(name,id,thumb);
							}
							else
							{
								requestSendMessage(name,id,thumb);	
							}
						}
						,params);
					}
				}
				else if(response.errorCode_=='limit Exceeded')
				{
					alert("You cannot send Invitations anymore.");	
				}
			}
		);
		
	}
	else
	{
		var params = {};
		params[opensocial.Message.Field.TITLE]="Hangout Invitation";
		var body='Add the App here :'+domainURL+'/AppInfo.aspx?appId='+appId;
		var message = opensocial.newMessage(body, params);
		var recipient = opensocial.DataRequest.Group.OWNER_FRIENDS;
		opensocial.requestSendMessage(recipient, message, 
			function(response)
			{
				if(response.errorCode_==null)
				{
					for(var r=0;r<response.data_.recipientIds.length;r++)
					{
						//FriendsSlider(0,'invitefriends',response.data_.recipientIds[r]);		
					}
				}
				else if(response.errorCode_=='limit Exceeded')
				{
					alert("You cannot send Invitations anymore.");	
				}
				/*if(typeof(response.text) != 'undefined' || response.text!="" || response.errors[0]!="Error 500" || response.text != '{}' || response.text != null)
				{
					var s=eval('('+response.text+')');
				}*/
			}
		);
	}
} 
function closewin(win)
{
	document.getElementById(win).style.display='none';
	document.getElementById('sample').style.display='none';
}

function confirmcancelhangout(cfm,hid,context,uids)
{
	if(cfm==displayMsg('Yes')) 
	{
		if(param != 'view')
		{
			document.getElementById('rsvploading'+hid).style.display='block';
			document.getElementById('cancel'+hid).style.display='none';
		}
		function cancel_callback(response) 
		{        
			if(typeof(response.text) == 'undefined' || response.text=="" || response.errors[0]=="Error 500" || response.text == '{}' || response.text == null)
			{
				err_conunt++;
				if(err_conunt>4)
				{
					var message = Customized_ErrorMessages('servlet');
					 alert(message);
					 err_conunt=0;
					showPages('hangout');
					 return;
				}
				else
				{
					confirmcancelhangout(cfm,hid,context,uids);
				}
			}
			else
			{
				var html = eval('('+response.text+')');  
				if(html.status==1)
				{
					u=0;
					if(param=='view')
					{
						getHtmlPage('hangout','','');
					}
					else if(param=='schedule')
					{
						getHangouts('scheduled',1,1);
						getHangouts('new',1,1);
						
					}
				}
			}
		};
		if(uids!='') 
		{
			var url=appServletURL+"/UpdateHangoutAction?"+ urlParams.join('');
			postdata = {hid : hid, uids : uids,action : 5, hostid: hostid , appid:appId , token:token};
			var params = {};
			params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
			params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
			params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;  
			gadgets.io.makeRequest(url,cancel_callback,params);
		}
		else
		 {
			var url=appServletURL+"/UpdateHangoutAction?"+ urlParams.join('');
			postdata = {hid : hid, uids : hostid,action : 5, hostid: hostid , appid:appId , token:token};
			var params = {};
			params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
			params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
			params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;   
			gadgets.io.makeRequest(url,cancel_callback,params);
		 }
		 document.getElementById('sample').style.display='none';
		 document.getElementById('csscancelhangout').style.display='none';
	}
	else if(cfm==displayMsg('No')) 
	{
		document.getElementById('sample').style.display='none';
		document.getElementById('csscancelhangout').style.display='none';
	}
}
///////redirecting to previous page//////////
function redirect_back()
{
	document.getElementById('viewHangout').style.display='block';
	document.getElementById('editHangout').style.display = 'none';
	document.getElementById('thankHangout').style.display='none';
	document.getElementById('thankEditHangout').style.display='none';
	document.getElementById('editmapwindow').style.display = 'none';
	document.getElementById('loading').style.display='none';
}
////////end og redirection function//////////
function ans(questionid)
{
var resid;
var answer;
var disp;
	switch(questionid)
	{
		case '1':
			resid='que1';
			answer= 'Answer for first question';
			disp='des1';
			break;
			
		case '2':
			resid='que2';
			answer= 'Answer for second question';
			disp='des2';
			break;
			
		case '3':
			resid='que3';
			answer= 'Answer for third question';
			disp='des3';
			break;
			
		case '4':
			resid='que4';
			answer= 'Answer for four question';
			disp='des4';
			break;
		
		case '5':
			resid='que5';
			answer= 'Answer for five question';
			disp='des5';
			break;
		
		case '6':
			resid='que6';
			answer= 'Answer for six question';
			disp='des6';
			break;
		
		case '7':
			resid='que7';
			answer= 'Answer for seven question';
			disp='des7';
			break;
			
		case '8':
			resid='que8';
			answer= 'Answer for eight question';
			disp='des8';
			break;
	
		case '9':
			resid='que9';
			answer= 'Answer for nine question';
			disp='des9';
			break;
			
		case '10':
			resid='que10';
			answer= 'Answer for eight question';
			disp='des10';
			break;
	}
	document.getElementById(resid).innerHTML= answer;
	if(document.getElementById(disp).style.display == 'block')
	{
		document.getElementById(disp).style.display = 'none';
	}
	else if(document.getElementById(disp).style.display == 'none')
	{
		document.getElementById(disp).style.display = 'block';
	}
}

function switchTab(junky)
{
	switch(junky)
	{
		case 'tab_hangout':
			document.getElementById('tab_hangout').className="selected";
			document.getElementById('tab_create').className="";
			document.getElementById('tab_past').className="";
			u=0;
			adjustPageHeight();
			break;

		case 'tab_past':
			document.getElementById('tab_hangout').className="";
			document.getElementById('tab_create').className="";
			document.getElementById('tab_past').className="selected";
			//document.getElementById('tab_invite').className="";
			
			adjustPageHeight();
			break;
	}
}

function topnav(toplinks,pge)
{
	switch(toplinks)
	{
	case 'about':
		document.getElementById('about').style.display='block';
		document.getElementById('coolapps').style.display='none';
		document.getElementById('help').style.display='none';
		document.getElementById('sample').style.display='block';
		if(pge=="eng_view")
		{
			document.getElementById('addMedia_div').style.display='none';
			document.getElementById('showMedia_div').style.display='none';
		}
		break;
	case 'coolapps':
		document.getElementById('about').style.display='none';
		document.getElementById('coolapps').style.display='block';
		document.getElementById('help').style.display='none';
		document.getElementById('sample').style.display='block';
		if(pge=="eng_view")
		{
			document.getElementById('addMedia_div').style.display='none';
			document.getElementById('showMedia_div').style.display='none';
		}
		break;
	 case 'help':
		document.getElementById('about').style.display='none';
		document.getElementById('coolapps').style.display='none';
		document.getElementById('help').style.display='block';
		document.getElementById('sample').style.display='block';
		if(pge=="eng_view")
		{
			document.getElementById('addMedia_div').style.display='none';
			document.getElementById('showMedia_div').style.display='none';
		}
		
		break;
	 case 'photos':
		document.getElementById('about').style.display='none';
		document.getElementById('coolapps').style.display='none';
		document.getElementById('help').style.display='none';
		document.getElementById('sample').style.display='block';
		document.getElementById('addMedia_div').style.display='block';
		document.getElementById('showMedia_div').style.display='none';
		document.getElementById('media_title').value='';
		document.getElementById('media_url').value='';
		media='photos';
		document.getElementById('m_id_vi').checked=false;
		document.getElementById('m_id_ph').checked=true;
		document.getElementById('m_id_vi').disabled=false;
		document.getElementById('m_id_ph').disabled=false;
		document.getElementById('media_btn').disabled=false;
		document.getElementById('sample_text').innerHTML='<font style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#999999">('+displayMsg("samplePurls")+': http://picasaweb.google.com/username/myalbum or http://www.flickr.com/photos/username)</font>';
		break;
	case 'videos':
		document.getElementById('about').style.display='none';
		document.getElementById('coolapps').style.display='none';
		document.getElementById('help').style.display='none';
		document.getElementById('sample').style.display='block';
		document.getElementById('addMedia_div').style.display='block';
		document.getElementById('showMedia_div').style.display='none';
		document.getElementById('media_title').value='';
		document.getElementById('media_url').value='';
		media='videos';
		document.getElementById('m_id_vi').checked=true;
		document.getElementById('m_id_ph').checked=false;
		document.getElementById('m_id_vi').disabled=false;
		document.getElementById('m_id_ph').disabled=false;
		document.getElementById('media_btn').disabled=false;
		document.getElementById('sample_text').innerHTML='<font style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#999999">('+displayMsg("sampleVurls")+': http://www.youtube.com/watch?v=videoid or http://video.google.com/videoplay?docid=videoid)</font>';
		break;
	case 'showMedia_div':
		document.getElementById('about').style.display='none';
		document.getElementById('coolapps').style.display='none';
		document.getElementById('help').style.display='none';
		document.getElementById('sample').style.display='block';
		document.getElementById('addMedia_div').style.display='none';
		document.getElementById('showMedia_div').style.display='block';
		break;
	}
}
function adjustPageHeight()
{
	gadgets.window.adjustHeight();
	if(document.getElementById('sample').style.display!='block')
	{
		setTimeout('adjustPageHeight()',1000);
	}
}
function showPages(page)
{
	if(page== 'hangout' || page=='viewHangout')
	{
		document.getElementById('tab_hangout').className="selected";
		document.getElementById('tab_create').className="";
		document.getElementById('tab_past').className="";
	}
	else if(page=='createhangout')
	{
		document.getElementById('tab_hangout').className="";
		document.getElementById('tab_create').className="selected";
		document.getElementById('tab_past').className="";
	}
	else if(page=='pasthangout')
	{
		document.getElementById('tab_hangout').className="";
		document.getElementById('tab_create').className="";
		document.getElementById('tab_past').className="selected";
	}
		
}

function trimAll(sString)
{
	var val;
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	if(sString == '')
	{
		val = 0;
	}
	else
	{
		val = 1;
	}
	return val;
}

function change_lang(c,l)
{
	if(c=='US' && l=='en')
	{
		cntr='eng';
	}
	else if(c=='BR' && l=='pt')
	{
		cntr='prt';	
	}
	else
	{
		cntr='eng';	
	}
	fetchAppPage();
}

///date.js////
Date.$VERSION=1.02;Date.LZ=function(x){return(x<0||x>9?"":"0")+x};Date.monthNames=new Array('January','February','March','April','May','June','July','August','September','October','November','December');Date.monthAbbreviations=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');Date.dayNames=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');Date.dayAbbreviations=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');Date.preferAmericanFormat=true;if(!Date.prototype.getFullYear){Date.prototype.getFullYear=function(){var yy=this.getYear();return(yy<1900?yy+1900:yy);};}Date.parseString=function(val,format){if(typeof(format)=="undefined"||format==null||format==""){var generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d','MMM-d','d-MMM');var monthFirst=new Array('M/d/y','M-d-y','M.d.y','M/d','M-d');var dateFirst=new Array('d/M/y','d-M-y','d.M.y','d/M','d-M');var checkList=new Array(generalFormats,Date.preferAmericanFormat?monthFirst:dateFirst,Date.preferAmericanFormat?dateFirst:monthFirst);for(var i=0;i<checkList.length;i++){var l=checkList[i];for(var j=0;j<l.length;j++){var d=Date.parseString(val,l[j]);if(d!=null){return d;}}}return null;};this.isInteger=function(val){for(var i=0;i<val.length;i++){if("1234567890".indexOf(val.charAt(i))==-1){return false;}}return true;};this.getInt=function(str,i,minlength,maxlength){for(var x=maxlength;x>=minlength;x--){var token=str.substring(i,i+x);if(token.length<minlength){return null;}if(this.isInteger(token)){return token;}}return null;};val=val+"";format=format+"";var i_val=0;var i_format=0;var c="";var token="";var token2="";var x,y;var year=new Date().getFullYear();var month=1;var date=1;var hh=0;var mm=0;var ss=0;var ampm="";while(i_format<format.length){c=format.charAt(i_format);token="";while((format.charAt(i_format)==c)&&(i_format<format.length)){token+=format.charAt(i_format++);}if(token=="yyyy"||token=="yy"||token=="y"){if(token=="yyyy"){x=4;y=4;}if(token=="yy"){x=2;y=2;}if(token=="y"){x=2;y=4;}year=this.getInt(val,i_val,x,y);if(year==null){return null;}i_val+=year.length;if(year.length==2){if(year>70){year=1900+(year-0);}else{year=2000+(year-0);}}}else if(token=="MMM"||token=="NNN"){month=0;var names=(token=="MMM"?(Date.monthNames.concat(Date.monthAbbreviations)):Date.monthAbbreviations);for(var i=0;i<names.length;i++){var month_name=names[i];if(val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()){month=(i%12)+1;i_val+=month_name.length;break;}}if((month<1)||(month>12)){return null;}}else if(token=="EE"||token=="E"){var names=(token=="EE"?Date.dayNames:Date.dayAbbreviations);for(var i=0;i<names.length;i++){var day_name=names[i];if(val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()){i_val+=day_name.length;break;}}}else if(token=="MM"||token=="M"){month=this.getInt(val,i_val,token.length,2);if(month==null||(month<1)||(month>12)){return null;}i_val+=month.length;}else if(token=="dd"||token=="d"){date=this.getInt(val,i_val,token.length,2);if(date==null||(date<1)||(date>31)){return null;}i_val+=date.length;}else if(token=="hh"||token=="h"){hh=this.getInt(val,i_val,token.length,2);if(hh==null||(hh<1)||(hh>12)){return null;}i_val+=hh.length;}else if(token=="HH"||token=="H"){hh=this.getInt(val,i_val,token.length,2);if(hh==null||(hh<0)||(hh>23)){return null;}i_val+=hh.length;}else if(token=="KK"||token=="K"){hh=this.getInt(val,i_val,token.length,2);if(hh==null||(hh<0)||(hh>11)){return null;}i_val+=hh.length;hh++;}else if(token=="kk"||token=="k"){hh=this.getInt(val,i_val,token.length,2);if(hh==null||(hh<1)||(hh>24)){return null;}i_val+=hh.length;hh--;}else if(token=="mm"||token=="m"){mm=this.getInt(val,i_val,token.length,2);if(mm==null||(mm<0)||(mm>59)){return null;}i_val+=mm.length;}else if(token=="ss"||token=="s"){ss=this.getInt(val,i_val,token.length,2);if(ss==null||(ss<0)||(ss>59)){return null;}i_val+=ss.length;}else if(token=="a"){if(val.substring(i_val,i_val+2).toLowerCase()=="am"){ampm="AM";}else if(val.substring(i_val,i_val+2).toLowerCase()=="pm"){ampm="PM";}else{return null;}i_val+=2;}else{if(val.substring(i_val,i_val+token.length)!=token){return null;}else{i_val+=token.length;}}}if(i_val!=val.length){return null;}if(month==2){if(((year%4==0)&&(year%100!=0))||(year%400==0)){if(date>29){return null;}}else{if(date>28){return null;}}}if((month==4)||(month==6)||(month==9)||(month==11)){if(date>30){return null;}}if(hh<12&&ampm=="PM"){hh=hh-0+12;}else if(hh>11&&ampm=="AM"){hh-=12;}return new Date(year,month-1,date,hh,mm,ss);};Date.isValid=function(val,format){return(Date.parseString(val,format)!=null);};Date.prototype.isBefore=function(date2){if(date2==null){return false;}return(this.getTime()<date2.getTime());};Date.prototype.isAfter=function(date2){if(date2==null){return false;}return(this.getTime()>date2.getTime());};Date.prototype.equals=function(date2){if(date2==null){return false;}return(this.getTime()==date2.getTime());};Date.prototype.equalsIgnoreTime=function(date2){if(date2==null){return false;}var d1=new Date(this.getTime()).clearTime();var d2=new Date(date2.getTime()).clearTime();return(d1.getTime()==d2.getTime());};Date.prototype.format=function(format){format=format+"";var result="";var i_format=0;var c="";var token="";var y=this.getYear()+"";var M=this.getMonth()+1;var d=this.getDate();var E=this.getDay();var H=this.getHours();var m=this.getMinutes();var s=this.getSeconds();var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;var value=new Object();if(y.length<4){y=""+(+y+1900);}value["y"]=""+y;value["yyyy"]=y;value["yy"]=y.substring(2,4);value["M"]=M;value["MM"]=Date.LZ(M);value["MMM"]=Date.monthNames[M-1];value["NNN"]=Date.monthAbbreviations[M-1];value["d"]=d;value["dd"]=Date.LZ(d);value["E"]=Date.dayAbbreviations[E];value["EE"]=Date.dayNames[E];value["H"]=H;value["HH"]=Date.LZ(H);if(H==0){value["h"]=12;}else if(H>12){value["h"]=H-12;}else{value["h"]=H;}value["hh"]=Date.LZ(value["h"]);value["K"]=value["h"]-1;value["k"]=value["H"]+1;value["KK"]=Date.LZ(value["K"]);value["kk"]=Date.LZ(value["k"]);if(H>11){value["a"]="PM";}else{value["a"]="AM";}value["m"]=m;value["mm"]=Date.LZ(m);value["s"]=s;value["ss"]=Date.LZ(s);while(i_format<format.length){c=format.charAt(i_format);token="";while((format.charAt(i_format)==c)&&(i_format<format.length)){token+=format.charAt(i_format++);}if(typeof(value[token])!="undefined"){result=result+value[token];}else{result=result+token;}}return result;};Date.prototype.getDayName=function(){return Date.dayNames[this.getDay()];};Date.prototype.getDayAbbreviation=function(){return Date.dayAbbreviations[this.getDay()];};Date.prototype.getMonthName=function(){return Date.monthNames[this.getMonth()];};Date.prototype.getMonthAbbreviation=function(){return Date.monthAbbreviations[this.getMonth()];};Date.prototype.clearTime=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this;};Date.prototype.add=function(interval,number){if(typeof(interval)=="undefined"||interval==null||typeof(number)=="undefined"||number==null){return this;}number=+number;if(interval=='y'){this.setFullYear(this.getFullYear()+number);}else if(interval=='M'){this.setMonth(this.getMonth()+number);}else if(interval=='d'){this.setDate(this.getDate()+number);}else if(interval=='w'){var step=(number>0)?1:-1;while(number!=0){this.add('d',step);while(this.getDay()==0||this.getDay()==6){this.add('d',step);}number-=step;}}else if(interval=='h'){this.setHours(this.getHours()+number);}else if(interval=='m'){this.setMinutes(this.getMinutes()+number);}else if(interval=='s'){this.setSeconds(this.getSeconds()+number);}return this;};
//calpopup//
var cp_timeoutDelay=2000;var cp_timeoutId=false;var cp_location=1;var g_startDay=0;var g_Calendar;function Calendar(){g_Calendar=this;this.daysOfWeek="Sun Mon Tue Wed Thu Fri Sat".split(" ");this.months="January February March April May June July August September October November December".split(" ");this.daysInMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);this.containerLayer=null;this.dayMask=[1,1,1,1,1,1,1];this.Holidays=null;this.showHolidays=true;}Calendar.prototype.show=function(e,target,dateFormat,dateFrom,dateTo,menuYearFrom,menuYearTo){if(!document.getElementById){alert("This browser is not suppored for a calendar popup.");return;}if(!document.getElementById(target)){alert("Error: input field \""+target+"\" does not exist.");return;}this.containerLayer=document.getElementById('calcontainer');if(!this.containerLayer){this.containerLayer=document.createElement('div');this.containerLayer.id='calcontainer';this.containerLayer.onmouseout=calendarTimeout;this.containerLayer.onmouseover=calendarClearTimeout;this.containerLayer.onclick=this.handleClick;document.body.insertBefore(this.containerLayer,document.body.childNodes[0]);}if(this.isVisible()){this.hide();return;}calendarClearTimeout();var elSrc;if(!e){e=window.event;}if(e.target){elSrc=e.target;}else if(e.srcElement){elSrc=e.srcElement;}e.cancelBubble=true;if(e.stopPropagation){e.stopPropagation();}var x,y,obj;x=y=0;if(cp_location==1){obj=document.getElementById(target);}else{obj=elSrc;}if(obj.offsetParent){while(obj){x+=obj.offsetLeft;y+=obj.offsetTop;obj=obj.offsetParent;}}else{x=obj.x;y=obj.y;}if(cp_location==1){var yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;}else if(document.body){yScroll=document.body.scrollTop;}this.containerLayer.style.left=x+"px";if((y+document.getElementById(target).offsetHeight+1+this.containerLayer.offsetHeight)>this.getWindowHeight()+yScroll){this.containerLayer.style.top=((y-this.containerLayer.offsetHeight)-1)+"px";}else{this.containerLayer.style.top=(y+document.getElementById(target).offsetHeight+1)+"px";}}else{this.containerLayer.style.left=(x+elSrc.offsetWidth+1)+"px";this.containerLayer.style.top=y+"px";}this.dateFrom=dateFrom||new Date(1900,0,1);this.dateFromDay=this.padZero(this.dateFrom.getDate());this.dateFromMonth=this.padZero(this.dateFrom.getMonth());this.dateFromYear=this.dateFrom.getFullYear();this.dateTo=dateTo||new Date(3000,0,1);this.dateToDay=this.padZero(this.dateTo.getDate());this.dateToMonth=this.padZero(this.dateTo.getMonth());this.dateToYear=this.dateTo.getFullYear();this.dateToday=new Date();this.tYear=this.dateToday.getFullYear();this.tMonth=this.dateToday.getMonth();this.tDay=this.dateToday.getDate();if(dateFormat){this.dateFormat=dateFormat;}else if(dp_dateFormat){this.dateFormat=dp_dateFormat;}else if(!this.dateFormat){this.dateFormat='m/d/yyyy';}dp_dateFormat=this.dateFormat;if(this.dateFormat.indexOf('-')!=-1){this.dateDelim='-';}else if(this.dateFormat.indexOf('/')!=-1){this.dateDelim='/';}else if(this.dateFormat.indexOf('.')!=-1){this.dateDelim='.';}else if(this.dateFormat.indexOf(' ')!=-1){this.dateDelim=' ';}else{this.dateDelim='/';}this.target=target;var tmp=document.getElementById(this.target);tmp.className=tmp.className.replace("error","").replace("  "," ");if(tmp&&tmp.value&&tmp.value.split(this.dateDelim).length==3){var atmp=tmp.value.split(this.dateDelim);var delim=eval('/\\'+this.dateDelim+'/g');switch(this.dateFormat.replace(delim,"")){case'ddmmmyyyy':case'dmmmyyyy':this.day=1;this.year=this.oYear=parseInt(atmp[2],10);for(var i=0;i<this.months.length;i++){if(atmp[1].toLowerCase()==this.months[i].substr(0,3).toLowerCase()){this.month=this.oMonth=i;break;}}this.day=parseInt(atmp[0],10);break;case'ddmmyyyy':case'dmmyyyy':case'dmyyyy':this.day=1;this.year=this.oYear=parseInt(atmp[2],10);this.month=this.oMonth=parseInt(atmp[1]-1,10);this.day=parseInt(atmp[0],10);break;case'mmddyyyy':case'mddyyyy':case'mdyyyy':this.day=1;this.year=this.oYear=parseInt(atmp[2],10);this.month=this.oMonth=parseInt(atmp[0]-1,10);this.day=parseInt(atmp[1],10);break;case'yyyymmdd':this.day=1;this.year=this.oYear=parseInt(atmp[0],10);this.month=this.oMonth=parseInt(atmp[1]-1,10);this.day=parseInt(atmp[2],10);break;}}else{var theDate=new Date();this.year=this.oYear=theDate.getFullYear();this.month=this.oMonth=theDate.getMonth();this.day=this.oDay=theDate.getDate();}this.menuYearFrom=menuYearFrom||this.year-20;this.menuYearTo=menuYearTo||this.year;var tmpCurYear=(new Date()).getFullYear();if(this.menuYearTo<tmpCurYear)this.menuYearTo=tmpCurYear;this.menuYearTo++;this.writeString(this.buildString());this.containerLayer.style.visibility='visible';};Calendar.prototype.buildString=function(){var tmpStr='';var aHolidays=new Array();if(this.Holidays){for(var h=0;h<this.Holidays.length;h++){if(this.Holidays[h].date.getFullYear()==this.year&&this.Holidays[h].date.getMonth()==this.month){aHolidays[aHolidays.length]=this.Holidays[h];}}}if(document.all&&document.getElementById&&!window.Opera){if(navigator.appVersion.substr(22,3)!="5.0"){tmpStr='<iframe src="about:blank" scrolling="no" frameborder="0" style="width: '+this.containerLayer.offsetWidth+'px; height: '+this.containerLayer.offsetHeight+'px; z-index: -1; position: absolute; filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);"></iframe>';}}tmpStr+='<table cellspacing="0">';tmpStr+='<thead><tr><td colspan="7"><ul>\n'+'<li id="cp_prevMonth"><a href="javascript:g_Calendar.changeMonth(-1)" title="Go to previous month"><span>&lt;</span></a></li>\n'+'<li id="cp_monthMenu"><a href="javascript:g_Calendar.openMenuMonths()" title="Open months menu">'+this.months[this.month]+'</a>\n'+'<ul id="cp_months"><li><a href="javascript:g_Calendar.clickMonth(0)">January</a></li><li><a href="javascript:g_Calendar.clickMonth(1)">February</a></li><li><a href="javascript:g_Calendar.clickMonth(2)">March</a></li><li><a href="javascript:g_Calendar.clickMonth(3)">April</a></li><li><a href="javascript:g_Calendar.clickMonth(4)">May</a></li><li><a href="javascript:g_Calendar.clickMonth(5)">June</a></li><li><a href="javascript:g_Calendar.clickMonth(6)">July</a></li><li><a href="javascript:g_Calendar.clickMonth(7)">August</a></li><li><a href="javascript:g_Calendar.clickMonth(8)">September</a></li><li><a href="javascript:g_Calendar.clickMonth(9)">October</a></li><li><a href="javascript:g_Calendar.clickMonth(10)">November</a></li><li><a href="javascript:g_Calendar.clickMonth(11)">December</a></li></ul></li>\n'+'<li id="cp_nextMonth"><a href="javascript:g_Calendar.changeMonth(1)" title="Go to next month"><span>&gt;</span></a></li>\n'+'<li id="cp_prevYear"><a href="javascript:g_Calendar.changeYear(-1)" title="Go to previous year"><span>&lt;</span></a></li>\n'+'<li id="cp_yearMenu"><a href="javascript:g_Calendar.openMenuYears();" title="Open years menu">'+this.year+'</a>\n';if(this.menuYearTo-this.menuYearFrom>7){tmpStr+='<ul id="cp_years" style="overflow: auto; overflow-x: hidden; overflow-y: auto;">';}else{tmpStr+='<ul id="cp_years">';}var menuYearTo=this.menuYearTo;if(menuYearTo<=this.year)menuYearTo=this.year+1;for(var y=this.menuYearFrom;y<menuYearTo;y++){tmpStr+='<li><a href="javascript:g_Calendar.clickYear('+y+')">'+y+'</a></li>';}tmpStr+='</ul></li>\n<li id="cp_nextYear"><a href="javascript:g_Calendar.changeYear(1)" title="Go to next year"><span>&gt;</span></a></li>\n</ul></td></tr>';var iCount=1;var iFirstDOM=(7+this.getFirstDOM()-g_startDay)%7;var iDaysInMonth=this.getDaysInMonth();tmpStr+='<tr>';for(var i=0;i<7;i++){tmpStr+='<th>'+this.daysOfWeek[(g_startDay+i)%7]+'</th>';}var dtToday=new Date();tmpStr+='</tr></thead><tfoot><tr><td colspan="7">Today is: <a href="javascript:g_Calendar.clickToday()" title="Go to current month">'+(/^d/.test(this.dateFormat)?dtToday.getDate()+' '+this.months[dtToday.getMonth()]+' ':this.months[dtToday.getMonth()]+' '+dtToday.getDate()+', ')+dtToday.getFullYear()+'</a></td></tr></tfoot><tbody>';var tmpFrom=parseInt(''+this.dateFromYear+this.dateFromMonth+this.dateFromDay,10);var tmpTo=parseInt(''+this.dateToYear+this.dateToMonth+this.dateToDay,10);var tmpCompare;for(var j=1;j<=6;j++){tmpStr+='<tr>';for(i=1;i<=7;i++){var bShowDay=true;var sTitle='';for(h=0;h<aHolidays.length;h++){if(aHolidays[h].date.getDate()==iCount){if(!this.showHolidays)bShowDay=false;sTitle=aHolidays[h].desc;}}tmpStr+='<td ';if((7*(j-1)+i)>=iFirstDOM+1&&iCount<=iDaysInMonth){if(iCount==this.day&&this.year==this.oYear&&this.month==this.oMonth){tmpStr+='class="calHighlightColor"';}else if(i==7-g_startDay||i==((7-g_startDay)%7)+1){tmpStr+='class="calWeekend"';}tmpStr+='>';if(this.dayMask[i-1]==0){bShowDay=false;}else{tmpCompare=parseInt(''+this.year+this.padZero(this.month)+this.padZero(iCount),10);if(!(tmpCompare>=tmpFrom&&tmpCompare<=tmpTo)){bShowDay=false;}}if(bShowDay){if(iCount==this.tDay&&this.year==this.tYear&&this.month==this.tMonth){tmpStr+='<a class="today"'+(sTitle==''?'':' title="'+sTitle+'"')+' href="javascript: g_Calendar.clickDay('+iCount+');"><strong>'+iCount+'</strong></a>';}else{tmpStr+='<a'+(sTitle==''?'':' title="'+sTitle+'"')+' href="javascript: g_Calendar.clickDay('+iCount+');">'+iCount+'</a>';}}else{if(iCount==this.tDay&&this.year==this.tYear&&this.month==this.tMonth){tmpStr+='<span'+(sTitle==''?'':' title="'+sTitle+'"')+' class="disabled today"><strong>'+iCount+'</strong></span>';}else{tmpStr+='<span'+(sTitle==''?'':' title="'+sTitle+'"')+' class="disabled">'+iCount+'</span>';}}iCount++;}else{if(i==7-g_startDay||i==((7-g_startDay)%7)+1){tmpStr+='class="calWeekend"';}tmpStr+=(sTitle==''?'':' title="'+sTitle+'"')+'>&nbsp;';}tmpStr+='</td>';}tmpStr+='</tr>';}tmpStr+='</tbody>';tmpStr+='</table>';return tmpStr;};Calendar.prototype.setDateFormat=function(dateFormat){this.dateFormat=dateFormat||'m/d/yyyy';dp_dateFormat=this.dateFormat;};Calendar.prototype.setDayMask=function(mask){var j=this.dayMask.length>mask.length?mask.length:this.dayMask.length;for(var i=0;i<j;i++)this.dayMask[i]=mask[i];return this.dayMask;};Calendar.prototype.setHolidays=function(obj,bShow){this.Holidays=obj;this.showHolidays=bShow;return obj;};Calendar.prototype.getFirstDOM=function(){var thedate=new Date();thedate.setDate(1);thedate.setMonth(this.month);thedate.setFullYear(this.year);return thedate.getDay();};Calendar.prototype.getDaysInMonth=function(){if(this.month!=1){return this.daysInMonth[this.month];}if(this.isLeapYear(this.year)){return 29;}return 28;};Calendar.prototype.isLeapYear=function(year){if(year%4==0&&((year%100!=0)||(year%400==0))){return true;}else{return false;}};Calendar.prototype.selectChange=function(el){this.month=el.selectedIndex;this.writeString(this.buildString());};Calendar.prototype.inputChange=function(el){var tmp=el;if(tmp.value>=1900&&tmp.value<=2100){this.year=tmp.value;this.writeString(this.buildString());}else{tmp.value=this.year;}};Calendar.prototype.changeYear=function(incr){if(incr==1){this.year++;}else{this.year--;}this.writeString(this.buildString());};Calendar.prototype.changeMonth=function(incr){if(this.month==11&&incr==1){this.month=0;this.year++;}else if(this.month==0&&incr==-1){this.month=11;this.year--;}else if(incr==1){this.month++;}else{this.month--;}this.writeString(this.buildString());};Calendar.prototype.clickDay=function(day){var el=document.getElementById(this.target);if(el){el.value=this.formatDateAsString(day,this.month,this.year);if(magicDate){magicDate(el);}el.focus();}this.hide();};Calendar.prototype.clickMonth=function(month){this.month=month;this.writeString(this.buildString());};Calendar.prototype.clickYear=function(year){this.year=year;this.writeString(this.buildString());};Calendar.prototype.clickToday=function(){var theDate=new Date();this.year=theDate.getFullYear();this.month=theDate.getMonth();this.writeString(this.buildString());};Calendar.prototype.formatDateAsString=function(day,month,year){var delim=eval('/\\'+this.dateDelim+'/g');switch(this.dateFormat.replace(delim,"")){case'ddmmmyyyy':return this.padZero(day)+this.dateDelim+this.months[month].substr(0,3)+this.dateDelim+year;case'dmmmyyyy':return day+this.dateDelim+this.months[month].substr(0,3)+this.dateDelim+year;case'ddmmyyyy':return this.padZero(day)+this.dateDelim+this.padZero(month+1)+this.dateDelim+year;case'dmmyyyy':return day+this.dateDelim+this.padZero(month+1)+this.dateDelim+year;case'mmddyyyy':return this.padZero((month+1))+this.dateDelim+this.padZero(day)+this.dateDelim+year;case'mddyyyy':return(month+1)+this.dateDelim+this.padZero(day)+this.dateDelim+year;case'mdyyyy':return(month+1)+this.dateDelim+day+this.dateDelim+year;case'yyyymmdd':return year+this.dateDelim+this.padZero(month+1)+this.dateDelim+this.padZero(day);default:return(month+1)+this.dateDelim+this.padZero(day)+this.dateDelim+year;}};Calendar.prototype.writeString=function(str){this.containerLayer.innerHTML=str;};Calendar.prototype.hide=function(){calendarClearTimeout();this.containerLayer.style.visibility='hidden';};Calendar.prototype.isVisible=function(){return this.containerLayer.style.visibility=='visible'?true:false;};Calendar.prototype.isHidden=function(){return this.containerLayer.style.visibility=='hidden'?true:false;};Calendar.prototype.padZero=function(num){return((num<=9)?("0"+num):num);};Calendar.prototype.getWindowHeight=function(){var windowHeight=0;if(typeof(window.innerHeight)=='number'){windowHeight=window.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowHeight=document.documentElement.clientHeight;}else if(document.body&&document.body.clientHeight){windowHeight=document.body.clientHeight;}return windowHeight;};Calendar.prototype.openMenu=function(e){var el=document.getElementById(e);if(!el){return;}if(el.className=="open"){el.className="";}else{el.className="open";}};Calendar.prototype.closeMenu=function(e){var el=document.getElementById(e);if(!el){return;}el.className="";};Calendar.prototype.openMenuMonths=function(){this.closeMenu('cp_years');this.openMenu('cp_months');};Calendar.prototype.openMenuYears=function(){this.closeMenu('cp_months');this.openMenu('cp_years');};Calendar.prototype.closeMenus=function(){this.closeMenu('cp_years');this.closeMenu('cp_months');};Calendar.prototype.handleClick=function(e){if(!e){e=window.event;}if(e.target){elSrc=e.target;}else if(e.srcElement){elSrc=e.srcElement;}if(e.pageX||e.pageY){x=e.pageX;y=e.pageY;}else if(e.clientX||e.clientY){x=e.clientX+document.body.scrollLeft;y=e.clientY+document.body.scrollTop;}if(y>parseInt(g_Calendar.containerLayer.style.top,10)+20){g_Calendar.closeMenus();}e.cancelBubble=true;if(e.stopPropagation){e.stopPropagation();}};function calendarTimeout(){if(cp_timeoutDelay){cp_timeoutId=setTimeout('g_Calendar.hide();',cp_timeoutDelay);}}function calendarClearTimeout(){if(cp_timeoutId){clearTimeout(cp_timeoutId);}}function cp_handleDocumentClick(e){var elSrc,x,y;if(!g_Calendar.containerLayer){return;}if(g_Calendar.isHidden()){return;}g_Calendar.hide();}Date.prototype.addDays=function(num){return new Date((num*(1000*60*60*24))+this.valueOf());};new Calendar(new Date());window.document.onclick=cp_handleDocumentClick;
//dateparser//
Array.prototype.indexOf=function(item){for(var i=0;i<this.length;i++){if(this[i]==item){return i;}}return-1;};Array.prototype.filter=function(test){var matches=[];for(var i=0;i<this.length;i++){if(test(this[i])){matches[matches.length]=this[i];}}return matches;};var monthNames="January February March April May June July August September October November December".split(" ");var weekdayNames="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" ");function parseMonth(month){var matches=monthNames.filter(function(item){return new RegExp("^"+month,"i").test(item);});if(matches.length==0){throw new Error("Invalid month string");}if(matches.length>1){throw new Error("Ambiguous month");}return monthNames.indexOf(matches[0]);}function parseWeekday(weekday){var matches=weekdayNames.filter(function(item){return new RegExp("^"+weekday,"i").test(item);});if(matches.length==0){throw new Error("Invalid day string");}if(matches.length>1){throw new Error("Ambiguous weekday");}return weekdayNames.indexOf(matches[0]);}var dateParsePatterns=[{re:/^tod/i,handler:function(){return new Date();}},{re:/^tom/i,handler:function(){var d=new Date();d.setDate(d.getDate()+1);return d;}},{re:/^yes/i,handler:function(){var d=new Date();d.setDate(d.getDate()-1);return d;}},{re:/^(\d{1,2})(st|nd|rd|th)?$/i,handler:function(bits){var d=new Date();d.setDate(parseInt(bits[1],10));return d;}},{re:/^(\d{1,2})(?:st|nd|rd|th)? (\w+)$/i,handler:function(bits){var d=new Date();d.setDate(1);d.setMonth(parseMonth(bits[2]));d.setDate(parseInt(bits[1],10));return d;}},{re:/^(\d{1,2})(?:st|nd|rd|th)? (\w+),? (\d{4})$/i,handler:function(bits){var d=new Date();d.setDate(1);d.setYear(bits[3]);d.setMonth(parseMonth(bits[2]));d.setDate(parseInt(bits[1],10));return d;}},{re:/^(\w+) (\d{1,2})(?:st|nd|rd|th)?$/i,handler:function(bits){var d=new Date();d.setDate(1);d.setMonth(parseMonth(bits[1]));d.setDate(parseInt(bits[2],10));return d;}},{re:/^(\w+) (\d{1,2})(?:st|nd|rd|th)?,? (\d{4})$/i,handler:function(bits){var d=new Date();d.setDate(1);d.setYear(bits[3]);d.setMonth(parseMonth(bits[1]));d.setDate(parseInt(bits[2],10));return d;}},{re:/^ne(?:xt)* (\w+)$/i,handler:function(bits){var d=new Date();var wd=d.getDay();var nwd=parseWeekday(bits[1]);var addDays=nwd-wd;if(nwd<=wd||(addDays+wd<7)){addDays+=7;}if(1==addDays){addDays+=7;}d.setDate(d.getDate()+addDays);return d;}},{re:/^la(?:st)* (\w+)$/i,handler:function(bits){var d=new Date();var wd=d.getDay();var nwd=parseWeekday(bits[1]);var addDays=(-1*(wd+7-nwd))%7;if(0==addDays){addDays=-7;}else if(-1==addDays){addDays-=7;}d.setDate(d.getDate()+addDays);return d;}},{re:/^th(?:is)* (\w+)$/i,handler:function(bits){var d=new Date();var wd=d.getDay();var nwd=parseWeekday(bits[1]);var addDays=nwd-wd;if(nwd<=wd){addDays+=7;}d.setDate(d.getDate()+addDays);return d;}},{re:/^fir(?:st)* (\w+)$/i,handler:function(bits){var d=new Date();d.setDate(1);var day=d.getDay();var newDay=parseWeekday(bits[1]);if(day==newDay){return d;}var addDays=newDay-day;if(newDay<day){addDays+=7;}d.setDate(d.getDate()+addDays);return d;}},{re:/^sec(?:ond)* (\w+)$/i,handler:function(bits){var d=new Date();d.setDate(1);var day=d.getDay();var newDay=parseWeekday(bits[1]);var addDays=newDay-day;if(newDay<day){addDays+=7;}addDays+=7;d.setDate(d.getDate()+addDays);return d;}},{re:/^thi(?:rd)* (\w+)$/i,handler:function(bits){var d=new Date();d.setDate(1);var day=d.getDay();var newDay=parseWeekday(bits[1]);var addDays=newDay-day;if(newDay<day){addDays+=7;}addDays+=14;d.setDate(d.getDate()+addDays);return d;}},{re:/^fo(?:urth)* (\w+)$/i,handler:function(bits){var d=new Date();d.setDate(1);var day=d.getDay();var newDay=parseWeekday(bits[1]);var addDays=newDay-day;if(newDay<day){addDays+=7;}addDays+=21;d.setDate(d.getDate()+addDays);return d;}},{re:/^fi(?:fth)* (\w+)$/i,handler:function(bits){var d=new Date();d.setDate(1);var day=d.getDay();var newDay=parseWeekday(bits[1]);var addDays=newDay-day;if(newDay<day){addDays+=7;}addDays+=28;d.setDate(d.getDate()+addDays);return d;}},{re:/(\d{1,2})\/(\d{1,2})\/(\d{4})/,handler:function(bits){var d=new Date();d.setDate(1);if(!dp_dateFormat||dp_dateFormat.substr(0,1)=='m'){d.setYear(bits[3]);d.setMonth(parseInt(bits[1],10)-1);d.setDate(parseInt(bits[2],10));}else{d.setYear(bits[3]);d.setMonth(parseInt(bits[2],10)-1);d.setDate(parseInt(bits[1],10));}return d;}},{re:/(\d{1,2})-(\d{1,2})-(\d{4})/,handler:function(bits){var d=new Date();d.setDate(1);if(!dp_dateFormat||dp_dateFormat.substr(0,1)=='m'){d.setYear(bits[3]);d.setMonth(parseInt(bits[1],10)-1);d.setDate(parseInt(bits[2],10));}else{d.setYear(bits[3]);d.setMonth(parseInt(bits[2],10)-1);d.setDate(parseInt(bits[1],10));}return d;}},{re:/(\d{1,2})\.(\d{1,2})\.(\d{4})/,handler:function(bits){var d=new Date();d.setDate(1);if(!dp_dateFormat||dp_dateFormat.substr(0,1)=='m'){d.setYear(bits[3]);d.setMonth(parseInt(bits[1],10)-1);d.setDate(parseInt(bits[2],10));}else{d.setYear(bits[3]);d.setMonth(parseInt(bits[2],10)-1);d.setDate(parseInt(bits[1],10));}return d;}},{re:/(\d{4})-(\d{1,2})-(\d{1,2})/,handler:function(bits){var d=new Date();d.setDate(1);d.setYear(parseInt(bits[1],10));d.setMonth(parseInt(bits[2],10)-1);d.setDate(parseInt(bits[3],10));return d;}}];function parseDateString(s){for(var i=0;i<dateParsePatterns.length;i++){var re=dateParsePatterns[i].re;var handler=dateParsePatterns[i].handler;var bits=re.exec(s);if(bits){return handler(bits);}}throw new Error("Invalid date string");}var dp_dateFormat;function dp_DateString(d){var dateDelim,delim;dp_dateFormat=dp_dateFormat||'m/d/yyyy';if(dp_dateFormat.indexOf('/')!=-1){delim=eval('/\\//g');dateDelim='/';}else if(dp_dateFormat.indexOf('-')!=-1){delim=eval('/\\-/g');dateDelim='-';}else if(dp_dateFormat.indexOf('.')!=-1){delim=eval('/\\./g');dateDelim='.';}else{delim=eval('/\\ /g');dateDelim=' ';}var month,day,year;month=d.getMonth();day=d.getDate();year=d.getFullYear();switch(dp_dateFormat.replace(delim,"")){case'ddmmmyyyy':return dp_padZero(day)+dateDelim+monthNames[month].substr(0,3)+dateDelim+year;case'dmmmyyyy':return day+dateDelim+monthNames[month].substr(0,3)+dateDelim+year;case'ddmmyyyy':return dp_padZero(day)+dateDelim+dp_padZero(month+1)+dateDelim+year;case'dmmyyyy':return day+dateDelim+dp_padZero(month+1)+dateDelim+year;case'mmddyyyy':return dp_padZero((month+1))+dateDelim+dp_padZero(day)+dateDelim+year;case'mddyyyy':return(month+1)+dateDelim+dp_padZero(day)+dateDelim+year;case'mdyyyy':return(month+1)+dateDelim+day+dateDelim+year;case'yyyymmdd':return year+dateDelim+dp_padZero(month+1)+dateDelim+dp_padZero(day);default:return(month+1)+dateDelim+day+dateDelim+year;}}function dp_padZero(n){return((n<=9)?("0"+n):n);}function magicDate(input,required){if(!required&&input.value==''){return true;}var bRet=true;var messagespan=input.id+'Msg';try{var d=parseDateString(input.value);input.value=dp_DateString(d);input.className='';var el=document.getElementById(messagespan);if(el){el.firstChild.nodeValue=d.toDateString();el.className='normal';}else{d.toDateString();}}catch(e){input.className='error';var message=e.message;if(!message.length||message.indexOf('is null or not an object')>-1){message='Invalid date string';}var el=document.getElementById(messagespan);if(el){el.firstChild.nodeValue=message;el.className='error';}else{alert(message);}bRet=false;}return bRet;}try{if(addEvent){var sEventType;;try{if(addDOMLoadEvent)sEventType="DOMContentLoaded";}catch(e){sEventType="load";}addEvent(window,sEventType,function(){var els=document.getElementsByTagName("input");for(var i=0;i<els.length;i++){if(/\bdateparse\b/.test(els[i].className)){addEvent(els[i],"blur",function(){magicDate(this);});addEvent(els[i],"focus",function(){if(this.className!='error')this.select();});}}});}}catch(e){}
//event//
function addEvent(element,type,handler){if(type=="DOMContentLoaded"||type=="domload"){addDOMLoadEvent(handler);return;}if(element.addEventListener){element.addEventListener(type,handler,false);}else{if(!handler.$$guid)handler.$$guid=addEvent.guid++;if(!element.events)element.events={};var handlers=element.events[type];if(!handlers){handlers=element.events[type]={};if(element["on"+type]){handlers[0]=element["on"+type];}}handlers[handler.$$guid]=handler;element["on"+type]=handleEvent;}};addEvent.guid=1;function removeEvent(element,type,handler){if(element.removeEventListener){element.removeEventListener(type,handler,false);}else{if(element.events&&element.events[type]){delete element.events[type][handler.$$guid];}}};function handleEvent(event){var returnValue=true;event=event||fixEvent(((this.ownerDocument||this.document||this).parentWindow||window).event);var handlers=this.events[event.type];for(var i in handlers){this.$$handleEvent=handlers[i];if(this.$$handleEvent(event)===false){returnValue=false;}}return returnValue;};function fixEvent(event){event.preventDefault=fixEvent.preventDefault;event.stopPropagation=fixEvent.stopPropagation;return event;};fixEvent.preventDefault=function(){this.returnValue=false;};fixEvent.stopPropagation=function(){this.cancelBubble=true;};if(!window.addEventListener){document.onreadystatechange=function(){if(window.onload&&window.onload!=handleEvent){addEvent(window,'load',window.onload);window.onload=handleEvent;}}}window.onDOMLoadEvents=new Array();window.DOMContentLoadedInitDone=false;function addDOMLoadEvent(listener){if(window.DOMContentLoadedInitDone){listener();return;}window.onDOMLoadEvents[window.onDOMLoadEvents.length]=listener;}function DOMContentLoadedInit(){if(window.DOMContentLoadedInitDone)return;window.DOMContentLoadedInitDone=true;for(var i=0;i<window.onDOMLoadEvents.length;i++){var func=window.onDOMLoadEvents[i];func();}}function DOMContentLoadedScheduler(){if(window.DOMContentLoadedInitDone)return true;if(/KHTML|WebKit/i.test(navigator.userAgent)){if(/loaded|complete/.test(document.readyState)){DOMContentLoadedInit();}else{setTimeout("DOMContentLoadedScheduler()",250);}}else if(document.getElementById("__ie_onload")){return true;}if(typeof DOMContentLoadedCustom=="function"){if(typeof document.getElementsByTagName!='undefined'&&(document.getElementsByTagName('body')[0]!=null||document.body!=null)){if(DOMContentLoadedCustom()){DOMContentLoadedInit();}else{setTimeout("DOMContentLoadedScheduler()",250);}}}return true;}setTimeout("DOMContentLoadedScheduler()",250);addEvent(window,"load",DOMContentLoadedInit);if(document.addEventListener)document.addEventListener("DOMContentLoaded",DOMContentLoadedInit,false);

